Class: StateChangers::DefaultStateChanger

Inherits:
Object
  • Object
show all
Defined in:
app/models/state_changers.rb

Overview

The Default State changer is used by the vast majority of plates. It creates a simple StateChange record in Sequencescape, specifying the new ‘target-state’ As a result, Sequencescape will attempt to transition the entire plate, or the specified wells.

Constant Summary collapse

FILTER_FAILS_ON =
%w[qc_complete failed cancelled].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, labware_uuid, user_uuid) ⇒ DefaultStateChanger

Returns a new instance of DefaultStateChanger.



19
20
21
22
23
# File 'app/models/state_changers.rb', line 19

def initialize(api, labware_uuid, user_uuid)
  @api = api
  @labware_uuid = labware_uuid
  @user_uuid = user_uuid
end

Instance Attribute Details

#labware_uuidObject (readonly)

Returns the value of attribute labware_uuid.



14
15
16
# File 'app/models/state_changers.rb', line 14

def labware_uuid
  @labware_uuid
end

#user_uuidObject (readonly)

Returns the value of attribute user_uuid.



14
15
16
# File 'app/models/state_changers.rb', line 14

def user_uuid
  @user_uuid
end

Instance Method Details

#contents_for(target_state) ⇒ Object

rubocop:enable Style/OptionalBooleanParameter



40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/state_changers.rb', line 40

def contents_for(target_state)
  return nil unless FILTER_FAILS_ON.include?(target_state)

  # determine list of well locations requiring the state change
  well_locations_filtered = labware.wells.reject { |w| w.state == 'failed' }.map(&:location)

  # if no wells are in failed state then no need to send the contents subset
  return nil if well_locations_filtered.length == labware.wells.count

  well_locations_filtered
end

#labwareObject



52
53
54
# File 'app/models/state_changers.rb', line 52

def labware
  @labware ||= api.plate.find(labware_uuid)
end

#move_to!(state, reason = nil, customer_accepts_responsibility = false) ⇒ Object

rubocop:todo Style/OptionalBooleanParameter



26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/state_changers.rb', line 26

def move_to!(state, reason = nil, customer_accepts_responsibility = false)
  state_details = {
    target: labware_uuid,
    user: user_uuid,
    target_state: state,
    reason: reason,
    customer_accepts_responsibility: customer_accepts_responsibility,
    contents: contents_for(state)
  }
  api.state_change.create!(state_details)
end