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.



75
76
77
78
79
80
81
# File 'lib/ridl/optparse_ext.rb', line 75

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.



73
74
75
# File 'lib/ridl/optparse_ext.rb', line 73

def params
  @params
end

Instance Method Details

#define_params(spec = {}) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/ridl/optparse_ext.rb', line 111

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

#descriptionObject



107
108
109
# File 'lib/ridl/optparse_ext.rb', line 107

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

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



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

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