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

Class Method Details

.state_helper(names) ⇒ Object


10
11
12
13
14
15
16
# File 'app/models/transfer/state.rb', line 10

def self.state_helper(names)
  names.each do |name|
    module_eval do
      define_method("#{name}?") { state == name }
    end
  end
end

Instance Method Details

#default_stateObject


26
27
28
# File 'app/models/transfer/state.rb', line 26

def default_state
  nil
end

#stateObject

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”!


22
23
24
# File 'app/models/transfer/state.rb', line 22

def state
  state_from(transfer_requests_as_target)
end

#state_from(state_requests) ⇒ Object


30
31
32
33
34
35
# File 'app/models/transfer/state.rb', line 30

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