Class: LcpRuby::Workflow::Approval::CleanupHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/workflow/approval/cleanup_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ CleanupHandler

Returns a new instance of CleanupHandler.



13
14
15
# File 'lib/lcp_ruby/workflow/approval/cleanup_handler.rb', line 13

def initialize(context)
  @context = context
end

Class Method Details

.async?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/lcp_ruby/workflow/approval/cleanup_handler.rb', line 9

def self.async?
  false
end

.handles_eventObject



5
6
7
# File 'lib/lcp_ruby/workflow/approval/cleanup_handler.rb', line 5

def self.handles_event
  "_approval_cleanup"
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lcp_ruby/workflow/approval/cleanup_handler.rb', line 17

def call
  record = @context[:record]
  changes = @context[:changes] || {}

  workflow_def = record.workflow_definition
  return unless workflow_def&.has_approvals?

  # Determine which state we just left
  field = workflow_def.field
  old_state = changes.dig(field, 0)
  return unless old_state

  approval_def = workflow_def.approval_for(old_state)
  return unless approval_def

  Engine.cancel(record, workflow_def, old_state)
end