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

Raises:

  • (RuntimeError)


244
245
246
247
248
249
# File 'lib/ridl/optparse_ext.rb', line 244

def define_group(id, options = {}, &block)
  id = id.to_sym
  raise RuntimeError, "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



282
283
284
285
286
287
288
289
# File 'lib/ridl/optparse_ext.rb', line 282

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



266
267
268
269
270
# File 'lib/ridl/optparse_ext.rb', line 266

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



252
253
254
255
256
257
258
259
# File 'lib/ridl/optparse_ext.rb', line 252

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



274
275
276
277
278
279
280
# File 'lib/ridl/optparse_ext.rb', line 274

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



262
263
264
# File 'lib/ridl/optparse_ext.rb', line 262

def undefine_group(id)
  @option.groups.delete(id.to_sym)
end

#without_param(id) ⇒ Object Also known as: without_set, without_params



292
293
294
295
296
297
298
# File 'lib/ridl/optparse_ext.rb', line 292

def without_param(id)
  if @option.groups.has_key?(:default)
    modify_group :default do |grpcfg|
      grpcfg.without_set("#{id}_set")
    end
  end
end