Class: SanUltari::CommandWrapper
- Inherits:
-
Object
- Object
- SanUltari::CommandWrapper
- Defined in:
- lib/sanultari/command_wrapper.rb
Instance Attribute Summary collapse
-
#clazz ⇒ Object
Returns the value of attribute clazz.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #add_param(param_name, options) ⇒ Object
- #freeze! ⇒ Object
- #freeze? ⇒ Boolean
-
#initialize(name, clazz, params = nil, options = nil) ⇒ CommandWrapper
constructor
A new instance of CommandWrapper.
- #run(args = nil, options = nil) ⇒ Object
Constructor Details
#initialize(name, clazz, params = nil, options = nil) ⇒ CommandWrapper
Returns a new instance of CommandWrapper.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sanultari/command_wrapper.rb', line 6 def initialize name, clazz, params = nil, = nil @name = name @clazz = clazz @params = params @params ||= [] @options = @options ||= {} @freeze = false @required_param_count = 0 # TODO : deprecate @args = [] end |
Instance Attribute Details
#clazz ⇒ Object
Returns the value of attribute clazz.
4 5 6 |
# File 'lib/sanultari/command_wrapper.rb', line 4 def clazz @clazz end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/sanultari/command_wrapper.rb', line 4 def @options end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/sanultari/command_wrapper.rb', line 4 def params @params end |
Instance Method Details
#add_param(param_name, options) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/sanultari/command_wrapper.rb', line 20 def add_param param_name, param = SanUltari::CommandParameter.new(param_name, ) if param.require? && !param.default @required_param_count += 1 end @params.push param end |
#freeze! ⇒ Object
40 41 42 |
# File 'lib/sanultari/command_wrapper.rb', line 40 def freeze! @freeze = true end |
#freeze? ⇒ Boolean
36 37 38 |
# File 'lib/sanultari/command_wrapper.rb', line 36 def freeze? @freeze end |
#run(args = nil, options = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sanultari/command_wrapper.rb', line 44 def run args = nil, = nil args ||= [] ||= [] unless args.length >= @required_param_count # TODO: standard output change puts "this command has #{@required_param_count} parameters at least" return end runner = @clazz.new # TODO options parsing , param_configs = set_values runner, args, set_defaults runner, param_configs if runner.public_method(@name).parameters.length > 0 runner.public_send @name, *@args else runner.public_send @name end end |