Class: IDL::OptionList::Option::Group::Configurator
- Inherits:
-
Object
- Object
- IDL::OptionList::Option::Group::Configurator
- Defined in:
- lib/ridl/optparse_ext.rb
Overview
ParamSet
Instance Method Summary collapse
- #define_param(id, options = {}, &block) ⇒ Object (also: #for_param, #with_param)
- #define_param_set(id, options = {}, &block) ⇒ Object (also: #for_params)
-
#initialize(grp) ⇒ Configurator
constructor
A new instance of Configurator.
- #modify_param_set(id, options = {}, &block) ⇒ Object (also: #modify_params, #with_params)
- #on_prepare(&block) ⇒ Object
- #without_param(id) ⇒ Object (also: #without_set, #without_params)
Constructor Details
#initialize(grp) ⇒ Configurator
Returns a new instance of Configurator.
154 155 156 |
# File 'lib/ridl/optparse_ext.rb', line 154 def initialize(grp) @group = grp end |
Instance Method Details
#define_param(id, options = {}, &block) ⇒ Object Also known as: for_param, with_param
182 183 184 185 186 187 |
# File 'lib/ridl/optparse_ext.rb', line 182 def define_param(id, ={}, &block) define_param_set("#{id}_set", ) do |pscfg| pscfg.with(id) pscfg.on_exec(&block) end end |
#define_param_set(id, options = {}, &block) ⇒ Object Also known as: for_params
164 165 166 167 168 169 |
# File 'lib/ridl/optparse_ext.rb', line 164 def define_param_set(id, = {}, &block) id = id.to_sym raise RuntimeError, "option parameter set [#{id}] already exists" if @group.sets.has_key?(id) @group.sets[id] = ParamSet.new() block.call(ParamSet::Configurator.new(@group.sets[id])) if block_given? end |
#modify_param_set(id, options = {}, &block) ⇒ Object Also known as: modify_params, with_params
172 173 174 175 176 177 178 |
# File 'lib/ridl/optparse_ext.rb', line 172 def modify_param_set(id, = {}, &block) id = id.to_sym parms = [:params] ? .delete(:params) : .delete(:param) @group.sets[id] ||= ParamSet.new() @group.sets[id].define_params(parms) if parms block.call(ParamSet::Configurator.new(@group.sets[id])) if block_given? end |
#on_prepare(&block) ⇒ Object
158 159 160 161 162 |
# File 'lib/ridl/optparse_ext.rb', line 158 def on_prepare(&block) ext_klass = class << @group; self; end ext_klass.send(:define_method, :_prepare, &block) ext_klass.send(:protected, :_prepare) end |
#without_param(id) ⇒ Object Also known as: without_set, without_params
191 192 193 |
# File 'lib/ridl/optparse_ext.rb', line 191 def without_param(id) @group.sets.delete("#{id}_set") end |