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.
75 76 77 78 79 80 81 |
# File 'lib/ridl/optparse_ext.rb', line 75 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.
73 74 75 |
# File 'lib/ridl/optparse_ext.rb', line 73 def params @params end |
Instance Method Details
#define_params(spec = {}) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/ridl/optparse_ext.rb', line 111 def define_params(spec = {}) case spec when String, Hash define_param(spec) when Array spec.each { |p| define_param(p) } end end |
#description ⇒ Object
107 108 109 |
# File 'lib/ridl/optparse_ext.rb', line 107 def description @params.values.inject(@description) { |list, vopt| list.concat(vopt[:description] || []) } end |
#run(param, options, *handler_args) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ridl/optparse_ext.rb', line 83 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 |