Class: FlowCore::Token
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- FlowCore::Token
- Defined in:
- app/models/flow_core/token.rb
Instance Method Summary collapse
- #can_consume? ⇒ Boolean
- #can_lock? ⇒ Boolean
- #can_terminate? ⇒ Boolean
- #consume(by:) ⇒ Object
- #consume!(by:) ⇒ Object
- #create_task! ⇒ Object
- #lock ⇒ Object
- #lock! ⇒ Object
- #terminate ⇒ Object
- #terminate! ⇒ Object
Instance Method Details
#can_consume? ⇒ Boolean
33 34 35 |
# File 'app/models/flow_core/token.rb', line 33 def can_consume? locked? end |
#can_lock? ⇒ Boolean
29 30 31 |
# File 'app/models/flow_core/token.rb', line 29 def can_lock? free? end |
#can_terminate? ⇒ Boolean
37 38 39 |
# File 'app/models/flow_core/token.rb', line 37 def can_terminate? free? || locked? end |
#consume(by:) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/models/flow_core/token.rb', line 49 def consume(by:) return false unless can_consume? update! stage: :consumed, consumed_by_task: by, consumed_at: Time.zone.now true end |
#consume!(by:) ⇒ Object
72 73 74 |
# File 'app/models/flow_core/token.rb', line 72 def consume!(by:) consume(by: by) || raise(FlowCore::InvalidTransition, "Can't consume Task##{id}") end |
#create_task! ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/flow_core/token.rb', line 80 def create_task! return if task_created transaction do place.output_transitions.each do |transition| transition.create_task_if_needed(token: self) end update! task_created: true end end |
#lock ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/flow_core/token.rb', line 41 def lock return false unless can_lock? update! stage: :locked, locked_at: Time.zone.now true end |
#lock! ⇒ Object
68 69 70 |
# File 'app/models/flow_core/token.rb', line 68 def lock! lock || raise(FlowCore::InvalidTransition, "Can't lock Task##{id}") end |
#terminate ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/models/flow_core/token.rb', line 59 def terminate return false unless can_terminate? update! stage: :terminated, terminated_at: Time.zone.now true end |
#terminate! ⇒ Object
76 77 78 |
# File 'app/models/flow_core/token.rb', line 76 def terminate! terminate || raise(FlowCore::InvalidTransition, "Can't terminate Task##{id}") end |