| 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.
| 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 => [] |
| dispatchers | [RW] |
Creates an instance of the parser. All the dispatchers located under the directory /commands/modules/ are loaded and instanced.
# 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
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.
# 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