class Uber::Options::Value
DEPRECATED! PLEASE USE UBER::OPTION.
Public Class Methods
new(value, options={})
click to toggle source
# File lib/uber/options.rb, line 32 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
call(context, *args)
click to toggle source
# File lib/uber/options.rb, line 44 def call(context, *args) return @value unless dynamic? evaluate_for(context, *args) end
Also aliased as: evaluate
callable?()
click to toggle source
# File lib/uber/options.rb, line 59 def callable? @value.is_a?(Uber::Callable) end
dynamic?()
click to toggle source
# File lib/uber/options.rb, line 51 def dynamic? @dynamic end
method?()
click to toggle source
# File lib/uber/options.rb, line 63 def method? @value.is_a?(Symbol) end
proc?()
click to toggle source
# File lib/uber/options.rb, line 55 def proc? @value.kind_of?(Proc) end
Private Instance Methods
callable!(context, *args)
click to toggle source
Callable
object is executed in its original context.
# File lib/uber/options.rb, line 88 def callable!(context, *args) @value.call(context, *args) end
evaluate_for(*args)
click to toggle source
# File lib/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/uber/options.rb, line 75 def method!(context, *args) context.send(@value, *args) end
proc!(context, *args)
click to toggle source
# File lib/uber/options.rb, line 79 def proc!(context, *args) if context.nil? @value.call(*args) else context.instance_exec(*args, &@value) end end