Class: IDL::OptionList::Option::Group::ParamSet
- Inherits:
-
Object
- Object
- IDL::OptionList::Option::Group::ParamSet
- Defined in:
- lib/ridl/optparse_ext.rb
Defined Under Namespace
Classes: Configurator
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #define_params(spec = {}) ⇒ Object
- #description ⇒ Object
-
#initialize(options) ⇒ ParamSet
constructor
A new instance of ParamSet.
- #run(param, options, *handler_args) ⇒ Object
Constructor Details
#initialize(options) ⇒ ParamSet
Returns a new instance of ParamSet.
78 79 80 81 82 83 84 |
# File 'lib/ridl/optparse_ext.rb', line 78 def initialize() @description = Array === [:description] ? [:description] : ([:description] || '').split('\n') @all_params = [:all_params] == true @params = {} parms = [:params] || [:param] define_params(parms) if parms end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
77 78 79 |
# File 'lib/ridl/optparse_ext.rb', line 77 def params @params end |
Instance Method Details
#define_params(spec = {}) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/ridl/optparse_ext.rb', line 114 def define_params(spec = {}) case spec when String, Hash define_param(spec) when Array spec.each {|p| define_param(p) } end end |
#description ⇒ Object
110 111 112 |
# File 'lib/ridl/optparse_ext.rb', line 110 def description @params.values.inject(@description) {|list, vopt| list.concat(vopt[:description] || []) } end |
#run(param, options, *handler_args) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ridl/optparse_ext.rb', line 86 def run(param, , *handler_args) key = to_key(param) if @all_params || @params.has_key?(key) param = key if String === param && @params.has_key?(key) param_arg = @params.has_key?(param) ? @params[param][:option_name] : param if self.respond_to?(:_exec, true) _exec(param_arg, , *handler_args) elsif @params.has_key?(param) if @params[param][:option_type] == :list [@params[param][:option_name]] ||= [] [@params[param][:option_name]] << (handler_args.size == 1 ? handler_args.shift : handler_args) elsif @params[param][:option_type] == :noop # do nothing else [@params[param][:option_name]] = handler_args.empty? ? (@params[param].has_key?(:option_value) ? @params[param][:option_value] : true) : (handler_args.size == 1 ? handler_args.shift : handler_args) end end return true end return false end |