Class: IDL::OptionList::Option

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

Defined Under Namespace

Classes: Configurator, Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(switch, options) ⇒ Option

Returns a new instance of Option.



306
307
308
309
310
311
312
# File 'lib/ridl/optparse_ext.rb', line 306

def initialize(switch, options)
  @switch = switch
  @type = options[:type] || TrueClass
  @separator = options[:separator] == true
  @description = Array === options[:description] ? options[:description] : (options[:description] ? options[:description].split('\n') : [''])
  @groups = {}
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



304
305
306
# File 'lib/ridl/optparse_ext.rb', line 304

def groups
  @groups
end

#separatorObject (readonly)

Returns the value of attribute separator.



304
305
306
# File 'lib/ridl/optparse_ext.rb', line 304

def separator
  @separator
end

#switchObject (readonly)

Returns the value of attribute switch.



304
305
306
# File 'lib/ridl/optparse_ext.rb', line 304

def switch
  @switch
end

#typeObject (readonly)

Returns the value of attribute type.



304
305
306
# File 'lib/ridl/optparse_ext.rb', line 304

def type
  @type
end

Instance Method Details

#description(indent = "") ⇒ Object



314
315
316
# File 'lib/ridl/optparse_ext.rb', line 314

def description(indent = "")
  @groups.values.inject(@description.dup) { |desc, h| desc.concat(h.description.collect { |desc| "\r#{indent}  #{desc}" }) }
end

#run(arg, options) ⇒ Object



318
319
320
321
322
# File 'lib/ridl/optparse_ext.rb', line 318

def run(arg, options)
  unless @groups.values.inject(false) { |f, h| h.run(arg, options) || f }
    raise ArgumentError, "unknown option [#{arg}] for switch '#{@switch}'"
  end
end