class Uber::Options::Value

Public Class Methods

new(value, options={}) click to toggle source
# File lib/garcon/utility/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

Public Instance Methods

dynamic?() click to toggle source
# File lib/garcon/utility/uber/options.rb, line 63
def dynamic?
  @dynamic
end
evaluate(context, *args) click to toggle source
# File lib/garcon/utility/uber/options.rb, line 57
def evaluate(context, *args)
  return @value unless dynamic?

  evaluate_for(context, *args)
end

Private Instance Methods

callable!(context, *args) click to toggle source

Callable object is executed in its original context.

# File lib/garcon/utility/uber/options.rb, line 84
def callable!(context, *args)
  @value.call(context, *args)
end
callable?() click to toggle source
# File lib/garcon/utility/uber/options.rb, line 92
def callable?
  @value.is_a?(Uber::Callable)
end
evaluate_for(*args) click to toggle source
# File lib/garcon/utility/uber/options.rb, line 68
def evaluate_for(*args)
  return proc!(*args)     if @proc
  return callable!(*args) if @callable
  method!(*args)
   # TODO: change to context.instance_exec and deprecate first argument.
end
method!(context, *args) click to toggle source
# File lib/garcon/utility/uber/options.rb, line 75
def method!(context, *args)
  context.send(@value, *args)
end
method?() click to toggle source
# File lib/garcon/utility/uber/options.rb, line 96
def method?
  @value.is_a?(Symbol)
end
proc!(context, *args) click to toggle source
# File lib/garcon/utility/uber/options.rb, line 79
def proc!(context, *args)
  context.instance_exec(*args, &@value)
end
proc?() click to toggle source
# File lib/garcon/utility/uber/options.rb, line 88
def proc?
  @value.kind_of?(Proc)
end