class CarryOut::Plan::Node
Attributes
action[RW]
connects_to[RW]
guarded_by[R]
return_transform[RW]
returns_as[RW]
Public Class Methods
new(action = nil)
click to toggle source
# File lib/carry_out/plan/node.rb, line 13 def initialize(action = nil) @action = action @messages = [] end
Public Instance Methods
call(context = {})
click to toggle source
# File lib/carry_out/plan/node.rb, line 18 def call(context = {}) return NodeResult.new unless @action return unless guard(context) result = @action.call do |a| @messages.map do |m| value = m[:source] if value.respond_to?(:call) value = GuardContext.new(context).instance_exec(context, &value) end a.send(m[:method], value) end end result = return_transform.call(result) unless return_transform.nil? NodeResult.new(result) end
guard_with(guard)
click to toggle source
# File lib/carry_out/plan/node.rb, line 39 def guard_with(guard) guard = guard.respond_to?(:call) ? guard : Proc.new { guard } guarded_by.push Guard.new(guard) end
guard_with_inverse(guard)
click to toggle source
# File lib/carry_out/plan/node.rb, line 44 def guard_with_inverse(guard) guard_with(guard) guarded_by.last.invert end
method_missing(method, *args, &block)
click to toggle source
# File lib/carry_out/plan/node.rb, line 53 def method_missing(method, *args, &block) if respond_to?(method) @messages.push({ method: method, source: block || (args.length == 0 ? true : args.first) }) end end
respond_to?(method, private = false)
click to toggle source
Calls superclass method
# File lib/carry_out/plan/node.rb, line 59 def respond_to?(method, private = false) (@action && @action.respond_to?(:has_parameter?) && @action.has_parameter?(method)) || super end
Private Instance Methods
guard(context = {})
click to toggle source
# File lib/carry_out/plan/node.rb, line 64 def guard(context = {}) guarded_by.empty? || guarded_by.all? { |g| g.call(context) } end