Module: Transfer::State::TubeState

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

Overview

Tube specific behaviour

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/transfer/state.rb', line 64

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

                         join_options = [
                           'LEFT OUTER JOIN `transfer_requests` transfer_requests_as_target ON transfer_requests_as_target.target_asset_id = `assets`.id'
                         ]

                         joins(join_options).where(transfer_requests_as_target: { state: states })
                       else
                         all
                       end
                     }
    scope :without_finished_tubes, lambda { |purpose|
      where.not(["assets.plate_purpose_id IN (?) AND transfer_requests_as_target.state = 'passed'", purpose.map(&:id)])
    }
  end
end