Class: LcpRuby::Workflow::Approval::DiscardHandler
- Inherits:
-
Object
- Object
- LcpRuby::Workflow::Approval::DiscardHandler
- Defined in:
- lib/lcp_ruby/workflow/approval/discard_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(context) ⇒ DiscardHandler
constructor
A new instance of DiscardHandler.
Constructor Details
#initialize(context) ⇒ DiscardHandler
Returns a new instance of DiscardHandler.
13 14 15 |
# File 'lib/lcp_ruby/workflow/approval/discard_handler.rb', line 13 def initialize(context) @context = context end |
Class Method Details
.async? ⇒ Boolean
9 10 11 |
# File 'lib/lcp_ruby/workflow/approval/discard_handler.rb', line 9 def self.async? false end |
.handles_event ⇒ Object
5 6 7 |
# File 'lib/lcp_ruby/workflow/approval/discard_handler.rb', line 5 def self.handles_event "after_discard" end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lcp_ruby/workflow/approval/discard_handler.rb', line 17 def call record = @context[:record] return unless Registry.available? workflow_def = record.workflow_definition return unless workflow_def&.has_approvals? request_model = Registry.request_model step_model = Registry.step_model task_model = Registry.task_model # Cancel all pending approval requests for this record model_name = record.class.name.demodulize.underscore active_requests = request_model.where( record_type: model_name, record_id: record.id, status: "pending" ) active_requests.each do |req| steps = step_model.where(approval_request_id: req.id) steps.each do |step| task_model.where( approval_step_id: step.id, status: %w[pending claimed] ).update_all(status: "cancelled") end steps.where(status: %w[pending active]).update_all(status: "skipped") req.update!(status: "cancelled") end end |