Module: Transfer::State
- Included in:
- Receptacle
- Defined in:
- app/models/transfer/state.rb
Overview
Provides scopes and methods to help find assets based on their state
Defined Under Namespace
Modules: PlateState, TubeState
Constant Summary collapse
- ALL_STATES =
These are all of the valid states but keep them in a priority order: in other words, ‘started’ is more important than ‘pending’ when there are multiple requests (like a plate where half the wells have been started, the others are failed).
%w[started qc_complete pending passed failed cancelled].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #default_state ⇒ Object
-
#state ⇒ Object
The state of an asset is based on the transfer requests for the asset.
- #state_from(state_requests) ⇒ Object
Class Method Details
.state_helper(names) ⇒ Object
10 11 12 |
# File 'app/models/transfer/state.rb', line 10 def self.state_helper(names) names.each { |name| module_eval { define_method("#{name}?") { state == name } } } end |
Instance Method Details
#default_state ⇒ Object
22 23 24 |
# File 'app/models/transfer/state.rb', line 22 def default_state nil end |
#state ⇒ Object
The state of an asset is based on the transfer requests for the asset. If they are all in the same state then it takes that state. Otherwise we take the “most optimum”!
18 19 20 |
# File 'app/models/transfer/state.rb', line 18 def state state_from(transfer_requests_as_target) end |
#state_from(state_requests) ⇒ Object
26 27 28 29 30 31 |
# File 'app/models/transfer/state.rb', line 26 def state_from(state_requests) unique_states = state_requests.map(&:state).uniq return unique_states.first if unique_states.size == 1 ALL_STATES.detect { |s| unique_states.include?(s) } || default_state || 'unknown' end |