Class Core::Service
In: core/service.rb
Parent: Commands::Dispatchers::Simple

TODO: move the Dispatcher module inside Core This class is inherits from Dispatchers::Simple because it provides some actions to the user.

Methods

dispatch   model   new  

Included Modules

Core::ServiceInterface

Constants

INFO = { :commands => { # TODO: does it make sense to have a 'clear' command here? wouldn't it # be better if the Parser of the View has some 'dispatching' # functionality of this kind? 'clear' => { :desc => 'clean the console window', :syntax => []

Attributes

dispatchers  [RW] 

Public Class methods

Creates an instance of the parser. All the dispatchers located under the directory /commands/modules/ are loaded and instanced.

[Source]

     # File core/service.rb, line 132
132:     def initialize
133:       reload
134:       
135:       # TODO: think about this, there should be a better way!!
136:       $model = Core::Model.new
137:     end

Public Instance methods

For a given command (cmd), this method walks through the registered dispatchers to see if anyone is able to run the command. If a valid dispatcher is found, the run method for this dispatcher is called passing along the command name and parameters entered by the user.

[Source]

     # File core/service.rb, line 146
146:     def dispatch(cmd, *args)
147:       $logger.debug {"dispatching command at #{self.class.to_s}"}
148:       $logger.debug {cmd}
149:       $logger.debug {args}
150:       
151:       found = false
152:       out = "command <b>#{cmd}</b> not implemented"
153:       self.dispatchers.each do |d|
154:         #         $logger.info {d.class.to_s}
155:         #         $logger.info {d.commands}
156:         next if !d.respond_to?('commands') ||
157:         d.commands == nil || 
158:         d.commands.size == 0
159:         
160:         $logger.debug {d.class.to_s}
161:         #$logger.debug {d.commands}
162:         if (d.commands.has_key? cmd)
163:           $logger.debug{d.commands.keys}
164:           #out = d.send('cmd_' + cmd, *params)
165:           out = d.run(cmd, *args)
166:           found = true
167:         end
168:         break if found
169:       end
170:       
171:       if out.instance_of?(Array)
172:         return out.join("\n")
173:       else
174:         return out
175:       end      
176:     end

[Source]

     # File core/service.rb, line 178
178:     def model
179:       $model
180:     end

[Validate]