Class: LcpRuby::Workflow::Approval::ActivationHandler

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ActivationHandler

Returns a new instance of ActivationHandler.



13
14
15
# File 'lib/lcp_ruby/workflow/approval/activation_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/activation_handler.rb', line 9

def self.async?
  false
end

.handles_eventObject



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

def self.handles_event
  "_approval_activate"
end

Instance Method Details

#callObject



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

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

  # Determine which state we just entered
  workflow_def = record.workflow_definition
  return unless workflow_def&.has_approvals?

  # Find the new state from changes
  field = workflow_def.field
  new_state = changes.dig(field, 1) || record.send(field)&.to_s
  return unless new_state

  approval_def = workflow_def.approval_for(new_state)
  return unless approval_def

  Engine.activate(record, workflow_def, new_state, user: user)
end