Class: IDL::OptionList::Option::Configurator
- Inherits:
-
Object
- Object
- IDL::OptionList::Option::Configurator
- Defined in:
- lib/ridl/optparse_ext.rb
Overview
Group
Instance Method Summary collapse
- #define_group(id, options = {}, &block) ⇒ Object (also: #for_group)
- #define_param(id, options = {}, &block) ⇒ Object (also: #for_param)
- #define_param_set(id, options = {}, &block) ⇒ Object (also: #for_set, #for_params)
-
#initialize(opt) ⇒ Configurator
constructor
A new instance of Configurator.
- #modify_group(id, options = {}, &block) ⇒ Object (also: #with_group)
- #on_exec(options = {}, &block) ⇒ Object
- #undefine_group(id) ⇒ Object
- #without_param(id) ⇒ Object (also: #without_set, #without_params)
Constructor Details
#initialize(opt) ⇒ Configurator
Returns a new instance of Configurator.
240 241 242 |
# File 'lib/ridl/optparse_ext.rb', line 240 def initialize(opt) @option = opt end |
Instance Method Details
#define_group(id, options = {}, &block) ⇒ Object Also known as: for_group
244 245 246 247 248 249 250 |
# File 'lib/ridl/optparse_ext.rb', line 244 def define_group(id, = {}, &block) id = id.to_sym raise "option group [#{id}] already exists" if @option.groups.has_key?(id) @option.groups[id] = Group.new(id, ) block.call(Group::Configurator.new(@option.groups[id])) if block_given? end |
#define_param(id, options = {}, &block) ⇒ Object Also known as: for_param
283 284 285 286 287 288 289 290 |
# File 'lib/ridl/optparse_ext.rb', line 283 def define_param(id, = {}, &block) modify_group :default, {test: true} do |grpcfg| grpcfg.define_param_set("#{id}_set", ) do |pscfg| pscfg.with(id) pscfg.on_exec(&block) end end end |
#define_param_set(id, options = {}, &block) ⇒ Object Also known as: for_set, for_params
267 268 269 270 271 |
# File 'lib/ridl/optparse_ext.rb', line 267 def define_param_set(id, = {}, &block) modify_group :default, {test: true} do |grpcfg| grpcfg.define_param_set(id, , &block) end end |
#modify_group(id, options = {}, &block) ⇒ Object Also known as: with_group
253 254 255 256 257 258 259 260 |
# File 'lib/ridl/optparse_ext.rb', line 253 def modify_group(id, = {}, &block) id = id.to_sym parms = [:params] ? .delete(:params) : .delete(:param) @option.groups[id] ||= Group.new(id, ) grpcfg = Group::Configurator.new(@option.groups[id]) grpcfg.modify_param_set(id, params: parms) if parms block.call(grpcfg) if block_given? end |
#on_exec(options = {}, &block) ⇒ Object
275 276 277 278 279 280 281 |
# File 'lib/ridl/optparse_ext.rb', line 275 def on_exec( = {}, &block) modify_group :default, {test: true} do |grpcfg| grpcfg.modify_param_set(:default, .merge({all_params: true})) do |pscfg| pscfg.on_exec(&block) end end end |
#undefine_group(id) ⇒ Object
263 264 265 |
# File 'lib/ridl/optparse_ext.rb', line 263 def undefine_group(id) @option.groups.delete(id.to_sym) end |
#without_param(id) ⇒ Object Also known as: without_set, without_params
293 294 295 296 297 298 299 |
# File 'lib/ridl/optparse_ext.rb', line 293 def without_param(id) if @option.groups.has_key?(:default) modify_group :default do |grpcfg| grpcfg.without_set("#{id}_set") end end end |