Module: Transfer::State::PlateState

Included in:
Plate
Defined in:
app/models/transfer/state.rb

Overview

Plate specific behaviour

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/transfer/state.rb', line 39

def self.included(base)
  base.class_eval do
    scope :in_state, lambda { |states|
                       states = Array(states).map(&:to_s)

                       # If all of the states are present there is no point in actually adding this set of conditions because we're
                       # basically looking for all of the plates.
                       if states.sort != ALL_STATES.sort
                         # Note that 'state IS NULL' is included here for plates that are stock plates, because they will not have any
                         # transfer requests coming into their wells and so we can assume they are pending (from the perspective of
                         # pulldown at least).
                         query_conditions = +'transfer_requests.state IN (?)'
                         query_conditions << ' OR (transfer_requests.state IS NULL AND plate_purposes.stock_plate=TRUE)' if states.include?('pending')

                         joins(:transfer_requests_as_target, :plate_purpose).where([query_conditions, states])
                       else
                         all
                       end
                     }
  end
end