module Race::Run
Attributes
main[RW]
Public Class Methods
add(opts)
click to toggle source
# File lib/system/run/run.rb, line 13 def self.add(opts) commands[opts[:name]] = opts end
load_commands()
click to toggle source
# File lib/system/run/run.rb, line 6 def self.load_commands Dir[File.join(File.dirname(__FILE__), 'commands', '*.rb')].each do |file| require file end self end
parse_command(ins = Commander::Runner.instance)
click to toggle source
# File lib/system/run/run.rb, line 17 def self.parse_command(ins = Commander::Runner.instance) commands.each_pair do |name, opts| name = Array(name) names = [name.reverse.join('-'), name.join(' ')] if name.length > 1 name = name.join(' ') ins.command name do |c| c.description = opts[:options][:description] c.summary = opts[:options][:summary] c.syntax = opts[:options][:syntax] (options_metadata = Array(opts[:options][:meta])).each do |o| option_data = [o[:switches], o[:type], o[:description], o[:optional]].compact.flatten(1) c.option *option_data o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last) end c.when_called do |args, options| object = opts[:class].new object.options = options run(object, opts[:method], args) end end end end
Protected Class Methods
commands()
click to toggle source
# File lib/system/run/run.rb, line 54 def self.commands @commands ||= {} end
hash_to_array(options)
click to toggle source
# File lib/system/run/run.rb, line 46 def self.hash_to_array(options) return_data = [] options.each do |k, v| return_data[k] = v end return_data end
run(obj, method, args)
click to toggle source
# File lib/system/run/run.rb, line 42 def self.run(obj, method, args) obj.send(method, *args) end