Class: IDL::OptionList::Option::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/ridl/optparse_ext.rb

Overview

Group

Instance Method Summary collapse

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, options = {}, &block)
  id = id.to_sym
  raise "option group [#{id}] already exists" if @option.groups.has_key?(id)

  @option.groups[id] = Group.new(id, options)
  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, options = {}, &block)
  modify_group :default, {test: true} do |grpcfg|
    grpcfg.define_param_set("#{id}_set", options) 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, options = {}, &block)
  modify_group :default, {test: true} do |grpcfg|
    grpcfg.define_param_set(id, options, &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, options = {}, &block)
  id = id.to_sym
  parms = options[:params] ? options.delete(:params) : options.delete(:param)
  @option.groups[id] ||= Group.new(id, options)
  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(options = {}, &block)
  modify_group :default, {test: true} do |grpcfg|
    grpcfg.modify_param_set(:default, options.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