Module: Request::Statemachine
- Extended by:
- ActiveSupport::Concern
- Included in:
- Request
- Defined in:
- app/models/request/statemachine.rb
Overview
rubocop:todo Metrics/ModuleLength
Constant Summary collapse
- COMPLETED_STATE =
%w[passed failed].freeze
- OPENED_STATE =
%w[pending blocked started].freeze
- ACTIVE =
%w[passed pending blocked started].freeze
- INACTIVE =
%w[failed cancelled].freeze
- SORT_ORDER =
%w[pending blocked hold started passed failed cancelled].freeze
Instance Method Summary collapse
- #cancellable? ⇒ Boolean
-
#change_decision! ⇒ void
deprecated
Deprecated.
Favour retrospective_pass and retrospective_fail! instead. It is incredibly unlikely that you wish to arbitrarily toggle the state of a request And instead you probably have an explicit target state in mind. Use that instead.
- #closed? ⇒ Boolean
- #failed_downstream! ⇒ Object
- #failed_upstream! ⇒ Object
- #finished? ⇒ Boolean
- #on_blocked ⇒ Object
- #on_cancelled ⇒ Object
- #on_failed ⇒ Object
- #on_hold ⇒ Object
- #on_passed ⇒ Object
-
#on_started ⇒ Object
Default behaviour on started is to do nothing.
- #open? ⇒ Boolean
- #terminated? ⇒ Boolean
-
#transfer_aliquots ⇒ Object
Aliquots are copied from the source asset to the target and updated with the project and study information from the request itself.
Instance Method Details
#cancellable? ⇒ Boolean
227 228 229 |
# File 'app/models/request/statemachine.rb', line 227 def cancellable? %w[pending cancelled].include?(state) end |
#change_decision! ⇒ void
Favour retrospective_pass and retrospective_fail! instead. It is incredibly unlikely that you wish to arbitrarily toggle the state of a request And instead you probably have an explicit target state in mind. Use that instead.
This method returns an undefined value.
Toggles passed request to failed, and failed requests to pass.
172 173 174 175 176 177 |
# File 'app/models/request/statemachine.rb', line 172 def change_decision! return retrospective_fail! if passed? return retrospective_pass! if failed? raise StandardError, 'Can only use change decision on passed or failed requests' end |
#closed? ⇒ Boolean
219 220 221 |
# File 'app/models/request/statemachine.rb', line 219 def closed? %w[passed failed cancelled aborted].include?(state) end |
#failed_downstream! ⇒ Object
[View source]
207 208 209 |
# File 'app/models/request/statemachine.rb', line 207 def failed_downstream! # Do nothing by default end |
#failed_upstream! ⇒ Object
[View source]
197 198 199 200 201 202 203 204 205 |
# File 'app/models/request/statemachine.rb', line 197 def failed_upstream! # Don't transition it again if it's already reached an end state return if terminated? # Only transition it if *all* upstream requests are failed or cancelled, not just the one we came from. return unless upstream_requests.all?(&:terminated?) fail_from_upstream! end |
#finished? ⇒ Boolean
211 212 213 |
# File 'app/models/request/statemachine.rb', line 211 def finished? passed? || failed? end |
#on_blocked ⇒ Object
[View source]
191 192 |
# File 'app/models/request/statemachine.rb', line 191 def on_blocked end |
#on_cancelled ⇒ Object
[View source]
188 189 |
# File 'app/models/request/statemachine.rb', line 188 def on_cancelled end |
#on_failed ⇒ Object
[View source]
182 183 |
# File 'app/models/request/statemachine.rb', line 182 def on_failed end |
#on_hold ⇒ Object
[View source]
194 195 |
# File 'app/models/request/statemachine.rb', line 194 def on_hold end |
#on_passed ⇒ Object
[View source]
185 186 |
# File 'app/models/request/statemachine.rb', line 185 def on_passed end |
#on_started ⇒ Object
Default behaviour on started is to do nothing.
150 151 152 |
# File 'app/models/request/statemachine.rb', line 150 def on_started # Some subclasses may call transfer_aliquots below. end |
#open? ⇒ Boolean
223 224 225 |
# File 'app/models/request/statemachine.rb', line 223 def open? %w[pending started].include?(state) end |
#terminated? ⇒ Boolean
215 216 217 |
# File 'app/models/request/statemachine.rb', line 215 def terminated? failed? || cancelled? end |
#transfer_aliquots ⇒ Object
Aliquots are copied from the source asset to the target and updated with the project and study information from the request itself.
156 157 158 159 160 161 162 163 |
# File 'app/models/request/statemachine.rb', line 156 def transfer_aliquots target_asset.aliquots << asset.aliquots.map do |aliquot| aliquot.dup.tap do |clone| clone.study_id = initial_study_id || aliquot.study_id clone.project_id = initial_project_id || aliquot.project_id end end end |