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


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

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 do |link|
    link.build!
  end
end

.included(base) ⇒ Object


75
76
77
78
79
# File 'app/models/submission/flexible_request_graph.rb', line 75

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


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/submission/flexible_request_graph.rb', line 97

def build!
  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|
        AssetLink.create_edge(source_asset.labware, target_asset.labware) if source_asset&.labware.present? && target_asset&.labware.present?

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

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

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


88
89
90
91
92
93
# File 'app/models/submission/flexible_request_graph.rb', line 88

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)

95
# File 'app/models/submission/flexible_request_graph.rb', line 95

def multiplexed?; false; end

#target_assetsObject


121
122
123
# File 'app/models/submission/flexible_request_graph.rb', line 121

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