Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/uber/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def call(context, *args)
context
end

ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)

def <<(proc)
super Uber::Option[proc, instance_exec: true]
end
Expand All @@ -36,6 +38,7 @@ module Build
def build!(context, *args)
builders.(context, *args)
end
ruby2_keywords(:build!) if respond_to?(:ruby2_keywords, true)
end
end
end
13 changes: 9 additions & 4 deletions lib/uber/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ module Uber
class Option
def self.[](value, options={}) # TODO: instance_exec: true
if value.is_a?(Proc)
return ->(context, *args) { context.instance_exec(*args, &value) } if options[:instance_exec]
return value unless options[:instance_exec]
wrapper = ->(context, *args) { context.instance_exec(*args, &value) }
elsif value.is_a?(Uber::Callable)
return value
elsif value.is_a?(Symbol)
wrapper = ->(context, *args){ context.send(value, *args) }
else
return ->(*) { value }
end

return value if value.is_a?(Uber::Callable)
return ->(context, *args){ context.send(value, *args) } if value.is_a?(Symbol)
->(*) { value }
wrapper.ruby2_keywords if wrapper.respond_to?(:ruby2_keywords)
wrapper
end
end
end
4 changes: 4 additions & 0 deletions lib/uber/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def eval(key, *args)
self[key].(*args)
end

ruby2_keywords(:evaluate, :eval) if respond_to?(:ruby2_keywords, true)

private

# DEPRECATED! PLEASE USE UBER::OPTION.
Expand All @@ -46,6 +48,7 @@ def call(context, *args)

evaluate_for(context, *args)
end
ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
alias_method :evaluate, :call

def dynamic?
Expand Down Expand Up @@ -88,6 +91,7 @@ def proc!(context, *args)
def callable!(context, *args)
@value.call(context, *args)
end
ruby2_keywords(:evaluate_for, :method!, :proc!, :callable!) if respond_to?(:ruby2_keywords, true)
end
end
end