module Workflow::Join
Constants
- DEVELOPER_ERROR
- GUARD_IS_NOT_WORKFLOW
- GUARD_PARAMS_ERROR
- GUARD_POINTCUT_ERROR
- VERSION
Public Instance Methods
guard(getter = nil, inner: nil, outer: nil, job: nil)
click to toggle source
# File lib/workflow/join.rb, line 95 def guard(getter = nil, inner: nil, outer: nil, job: nil) fail Workflow::WorkflowDefinitionError, GUARD_PARAMS_ERROR unless [getter, job, block_given?].one? fail Workflow::WorkflowDefinitionError, GUARD_POINTCUT_ERROR unless inner && (outer || job) guard = case getter ||= job when NilClass then Proc.new # block_given? == true, see L#97 check when Symbol, String then guard_for_instance_variable(getter) when Class then guard_for_class(getter) else fail Workflow::WorkflowDefinitionError, DEVELOPER_ERROR end (guards[inner.to_sym] ||= []) << [guard, (outer || ::Workflow::Join::Sidekiq::Job::DONE).to_sym] end
guards()
click to toggle source
# File lib/workflow/join.rb, line 91 def guards @guards ||= {} end
Private Instance Methods
guard_for_class(getter)
click to toggle source
# File lib/workflow/join.rb, line 125 def guard_for_class(getter) lambda do |host| Workflow::Join::Sidekiq::Job.lookup!(host, getter).tap do |job| job.run! if job.can_run? end end end
guard_for_instance_variable(getter)
click to toggle source
# File lib/workflow/join.rb, line 110 def guard_for_instance_variable(getter) 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 <= 0 host.send g end.tap do |guard_instance| fail Workflow::WorkflowDefinitionError, GUARD_IS_NOT_WORKFLOW % guard_instance \ unless guard_instance.nil? || guard_instance.is_a?(Workflow) end end end