70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/workflow/join.rb', line 70
def guard(getter = nil, inner: nil, outer: nil)
fail Workflow::WorkflowDefinitionError, GUARD_PARAMS_ERROR unless !getter.nil? ^ block_given?
fail Workflow::WorkflowDefinitionError, GUARD_POINTCUT_ERROR unless inner && outer
guard = if block_given?
Proc.new
else
g = getter.to_sym
lambda do |host|
case
when /\A@/ =~ g.to_s && host.instance_variable_defined?(g)
host.instance_variable_get(g)
when host.methods.include?(g) && host.method(g).arity.zero?
host.send g
end.tap do |guard_instance|
fail Workflow::WorkflowDefinitionError, GUARD_IS_NOT_WORKFLOW unless guard_instance.is_a?(Workflow)
end
end
end
(guards[inner.to_sym] ||= []) << [guard, outer.to_sym]
end
|