Module: Workflow::Join

Defined in:
lib/workflow/join.rb,
lib/workflow/join/simple.rb,
lib/workflow/join/version.rb,
lib/workflow/join/sidekiq/job.rb,
lib/workflow/join/active_record.rb,
lib/workflow/join/simple/pending_callbacks.rb,
lib/workflow/join/simple/pending_transitions.rb,
lib/workflow/join/active_record/pending_callbacks.rb,
lib/workflow/join/active_record/pending_transitions.rb

Defined Under Namespace

Modules: ActiveRecord, Sidekiq, Simple

Constant Summary collapse

GUARD_PARAMS_ERROR =
'One of: [guard instance variable, code block, job] is required'.freeze
GUARD_POINTCUT_ERROR =
'Both :inner and :outer state / :job are required'.freeze
GUARD_IS_NOT_WORKFLOW =
'Guard given must be a workflow instance, was: “%s”'.freeze
DEVELOPER_ERROR =
'Developer is an idiot, please excuse and file and issue'.freeze
VERSION =
'0.3.2'.freeze

Instance Method Summary collapse

Instance Method Details

#guard(getter = nil, inner: nil, outer: nil, job: nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# 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

#guardsObject



91
92
93
# File 'lib/workflow/join.rb', line 91

def guards
  @guards ||= {}
end