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

rubocop:todo Metrics/MethodLength


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

def self.included(base) # rubocop:todo Metrics/MethodLength
  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 = [
                # rubocop:todo Layout/LineLength
                'LEFT OUTER JOIN `transfer_requests` transfer_requests_as_target ON transfer_requests_as_target.target_asset_id = `assets`.id'
                # rubocop:enable Layout/LineLength
              ]

              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