Class: Uber::Options::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/uber/options.rb

Overview

TODO: rename to Value.

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ Value

Returns a new instance of Value.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/uber/options.rb', line 45

def initialize(value, options={})
  @value, @dynamic = value, options[:dynamic]

  @proc     = proc?
  @callable = callable?
  @method   = method?

  return if options.has_key?(:dynamic)

  @dynamic = @proc || @callable || @method
end

Instance Method Details

#callable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/uber/options.rb', line 71

def callable?
  @value.is_a?(Uber::Callable)
end

#dynamic?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/uber/options.rb', line 63

def dynamic?
  @dynamic
end

#evaluate(context, *args) ⇒ Object



57
58
59
60
61
# File 'lib/uber/options.rb', line 57

def evaluate(context, *args)
  return @value unless dynamic?

  evaluate_for(context, *args)
end

#method?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/uber/options.rb', line 75

def method?
  @value.is_a?(Symbol)
end

#proc?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/uber/options.rb', line 67

def proc?
  @value.kind_of?(Proc)
end