Module: PlatePurpose::RequestAttachment

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


39
40
41
42
43
44
# File 'app/models/plate_purpose/request_attachment.rb', line 39

def self.included(base)
  base.class_eval do
    class_attribute :connect_on
    class_attribute :connect_downstream
  end
end

Instance Method Details

#connect_requests(plate, state, contents = nil) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/plate_purpose/request_attachment.rb', line 7

def connect_requests(plate, state, contents = nil)
  return unless state == connect_on

  wells = plate.wells
  wells = wells.located_at(contents) unless contents.blank?

  wells.include_stock_wells.include_requests_as_target.includes(:transfer_requests_as_target).each do |target_well|
    source_wells = target_well.stock_wells
    submission_ids = target_well.transfer_requests_as_target.map(&:submission_id)

    source_wells.each do |source_well|
      # We may have multiple requests out of each well, however we're only concerned
      # about those associated with the active submission.
      upstream = source_well.requests.detect do |r|
        submission_ids.include?(r.submission_id)
      end

      # We need to find the downstream requests BEFORE connecting the upstream
      # This is because submission.next_requests tries to take a shortcut through
      # the target_asset if it is defined.
      upstream.next_requests.each { |ds| ds.update!(asset: target_well) } if connect_downstream

      # In some cases, such as the Illumina-C pipelines, requests might be
      # connected upfront. We don't want to touch these.
      next unless upstream.target_asset.nil?

      upstream.update!(target_asset: target_well)
      upstream.pass!
    end
  end
end

#transition_to(plate, state, user, contents = nil, customer_accepts_responsibility = false) ⇒ Object


2
3
4
5
# File 'app/models/plate_purpose/request_attachment.rb', line 2

def transition_to(plate, state, user, contents = nil, customer_accepts_responsibility = false)
  super
  connect_requests(plate, state, contents)
end