Module: Submission::FlexibleRequestGraph::ChainLink

Included in:
MultiplexedLink, UnplexedLink
Defined in:
app/models/submission/flexible_request_graph.rb

Overview

Builds all requests of a given request type and any target_assets The build! method automatically creates a link of the appropriate class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build!(request_type, multiplier, source_assets_qc_metrics, chain) ⇒ Object



86
87
88
89
# File 'app/models/submission/flexible_request_graph.rb', line 86

def self.build!(request_type, multiplier, source_assets_qc_metrics, chain)
  link_class = request_type.for_multiplexing? ? MultiplexedLink : UnplexedLink
  link_class.new(request_type, multiplier, source_assets_qc_metrics, chain).tap(&:build!)
end

.included(base) ⇒ Object



80
81
82
83
84
# File 'app/models/submission/flexible_request_graph.rb', line 80

def self.included(base)
  base.class_eval do
    attr_reader :request_type, :multiplier, :source_assets_qc_metrics, :target_assets_qc_metrics, :chain
  end
end

Instance Method Details

#build!Object

rubocop:todo Metrics/MethodLength



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/models/submission/flexible_request_graph.rb', line 103

def build! # rubocop:todo Metrics/AbcSize
  multiplier.times do |_|
    # Now we can iterate over the source assets and target assets building the requests between them.
    # Ensure that the request has the correct comments on it, and that the aliquots of the source asset
    # are transferred into the destination if the request does not do this in some manner itself.
    source_asset_metrics_target_assets do |source_asset, qc_metrics, target_asset|
      chain
        .order
        .create_request_of_type!(request_type, asset: source_asset, target_asset: target_asset)
        .tap do |request|
          if source_asset&.labware.present? && target_asset&.labware.present?
            AssetLink.create_edge(source_asset.labware, target_asset.labware)
          end

          request.qc_metrics = qc_metrics.compact.uniq
          request.update_responsibilities!

          if comments.present?
            comments.each { |comment| request.comments.create!(user: user, description: comment) }
          end
        end
    end
  end
  associate_built_requests!
end

#initialize(request_type, multiplier, source_assets_qc_metrics, chain) ⇒ Object



91
92
93
94
95
96
# File 'app/models/submission/flexible_request_graph.rb', line 91

def initialize(request_type, multiplier, source_assets_qc_metrics, chain)
  @request_type = request_type
  @multiplier = multiplier
  @source_assets_qc_metrics = source_assets_qc_metrics
  @chain = chain
end

#multiplexed?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/submission/flexible_request_graph.rb', line 98

def multiplexed?
  false
end

#target_assetsObject

rubocop:enable Metrics/MethodLength



131
132
133
# File 'app/models/submission/flexible_request_graph.rb', line 131

def target_assets
  target_assets_qc_metrics.map(&:asset).flatten.uniq
end