class Management::Command
Public Class Methods
all()
click to toggle source
# File lib/management/command.rb, line 5 def self.all @all ||= [] end
inherited(subclass)
click to toggle source
# File lib/management/command.rb, line 9 def self.inherited(subclass) all << subclass.new end
maxlen()
click to toggle source
# File lib/management/command.rb, line 13 def self.maxlen all.map(&:command_name).map(&:size).max end
Public Instance Methods
arg_list()
click to toggle source
# File lib/management/command.rb, line 29 def arg_list fn.parameters.map do |req, name| name = '<' + name.to_s.sub(/_names?/, '') + '>' case req when :opt then '[' + name + ']' when :rest then name + ' [...]' else name end end.join(' ') end
call_with(args, error_handler)
click to toggle source
# File lib/management/command.rb, line 51 def call_with(args, error_handler) arity = self.true_arity error_handler.call "not enough arguments" if args.count < arity.begin error_handler.call "too many arguments" if args.count > arity.end fn.call *args end
command_name()
click to toggle source
# File lib/management/command.rb, line 21 def command_name self.class.name. split('::'). drop(1). join(":"). downcase end
fn()
click to toggle source
# File lib/management/command.rb, line 17 def fn method(:run) end
help_string()
click to toggle source
# File lib/management/command.rb, line 40 def help_string sprintf " %-#{Command.maxlen + 2}s %s", command_name, arg_list end
true_arity()
click to toggle source
# File lib/management/command.rb, line 44 def true_arity min = fn.parameters.take_while{|req, name| req == :req}.count max = fn.parameters.count max = Float::INFINITY if max > 0 && fn.parameters.last.first == :rest min..max end