Class: AppKernel::Function::Options::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/appkernel/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, modifiers) ⇒ Option

Returns a new instance of Option.



201
202
203
204
205
206
207
208
# File 'lib/appkernel/function.rb', line 201

def initialize(name, modifiers)
  @name = name.to_sym
  @index = modifiers[:index]
  @required = modifiers[:required] == true
  @lookup = modifiers[:lookup] || modifiers[:parse]
  @type = modifiers[:type]
  @default = modifiers[:default]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



199
200
201
# File 'lib/appkernel/function.rb', line 199

def default
  @default
end

#indexObject (readonly)

Returns the value of attribute index.



199
200
201
# File 'lib/appkernel/function.rb', line 199

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



199
200
201
# File 'lib/appkernel/function.rb', line 199

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



199
200
201
# File 'lib/appkernel/function.rb', line 199

def type
  @type
end

Instance Method Details

#default?Boolean

Returns:



214
215
216
# File 'lib/appkernel/function.rb', line 214

def default?
  !@default.nil?
end

#required?Boolean

Returns:



210
211
212
# File 'lib/appkernel/function.rb', line 210

def required?
  @required
end

#resolve(o) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/appkernel/function.rb', line 218

def resolve(o)
  if o.nil? then nil  
  elsif @type
    if @type.kind_of?(Class) && o.kind_of?(@type) then o
    elsif @type.kind_of?(Enumerable) && @type.detect {|t| o.kind_of?(t)} then o
    elsif @lookup
      @lookup.call(o)
    elsif @type.respond_to?(:to_option)
      @type.to_option(o)
    else
      raise OptionsError, "don't know how to convert #{o} into #{@type}"
    end
  else
    @lookup ? @lookup.call(o) : o
  end                    
end