Class: IDL::OptionList::Option::Group::ParamSet

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

Defined Under Namespace

Classes: Configurator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ParamSet

Returns a new instance of ParamSet.



78
79
80
81
82
83
84
# File 'lib/ridl/optparse_ext.rb', line 78

def initialize(options)
  @description = Array === options[:description] ? options[:description] : (options[:description] || '').split('\n')
  @all_params = options[:all_params] == true
  @params = {}
  parms = options[:params] || options[:param]
  define_params(parms) if parms
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



77
78
79
# File 'lib/ridl/optparse_ext.rb', line 77

def params
  @params
end

Instance Method Details

#define_params(spec = {}) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/ridl/optparse_ext.rb', line 114

def define_params(spec = {})
  case spec
  when String, Hash
    define_param(spec)
  when Array
    spec.each {|p| define_param(p) }
  end
end

#descriptionObject



110
111
112
# File 'lib/ridl/optparse_ext.rb', line 110

def description
  @params.values.inject(@description) {|list, vopt| list.concat(vopt[:description] || []) }
end

#run(param, options, *handler_args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ridl/optparse_ext.rb', line 86

def run(param, options, *handler_args)
  key = to_key(param)
  if @all_params || @params.has_key?(key)
    param = key if String === param && @params.has_key?(key)
    param_arg = @params.has_key?(param) ? @params[param][:option_name] : param
    if self.respond_to?(:_exec, true)
      _exec(param_arg, options, *handler_args)
    elsif @params.has_key?(param)
      if @params[param][:option_type] == :list
        options[@params[param][:option_name]] ||= []
        options[@params[param][:option_name]] << (handler_args.size == 1 ? handler_args.shift : handler_args)
      elsif @params[param][:option_type] == :noop
        # do nothing
      else
        options[@params[param][:option_name]] = handler_args.empty? ?
            (@params[param].has_key?(:option_value) ? @params[param][:option_value] : true) :
            (handler_args.size == 1 ? handler_args.shift : handler_args)
      end
    end
    return true
  end
  return false
end