Class: Submission::FlexibleRequestGraph::RequestChain

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, source_assets, multiplexing_assets) ⇒ RequestChain

Returns a new instance of RequestChain.



22
23
24
25
26
27
28
29
# File 'app/models/submission/flexible_request_graph.rb', line 22

def initialize(order, source_assets, multiplexing_assets)
  @order = order
  @source_assets_qc_metrics = source_assets.map { |asset| Doublet.new(asset, asset.latest_stock_metrics(product)) }
  @multiplexing_assets = multiplexing_assets
  @preplexed = multiplexing_assets.present?
  @built = false
  @multiplexed = false
end

Instance Attribute Details

#builtObject (readonly) Also known as: built?

Returns the value of attribute built.



15
16
17
# File 'app/models/submission/flexible_request_graph.rb', line 15

def built
  @built
end

#multiplexedObject (readonly) Also known as: multiplexed?

Returns the value of attribute multiplexed.



15
16
17
# File 'app/models/submission/flexible_request_graph.rb', line 15

def multiplexed
  @multiplexed
end

#orderObject (readonly)

Returns the value of attribute order.



15
16
17
# File 'app/models/submission/flexible_request_graph.rb', line 15

def order
  @order
end

#preplexedObject (readonly) Also known as: preplexed?

Returns the value of attribute preplexed.



15
16
17
# File 'app/models/submission/flexible_request_graph.rb', line 15

def preplexed
  @preplexed
end

#source_assets_qc_metricsObject (readonly)

Returns the value of attribute source_assets_qc_metrics.



15
16
17
# File 'app/models/submission/flexible_request_graph.rb', line 15

def source_assets_qc_metrics
  @source_assets_qc_metrics
end

Instance Method Details

#build!Object

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/submission/flexible_request_graph.rb', line 31

def build!
  raise RequestChainError, 'Request chains can only be built once' if built?
  raise StandardError, 'No request types specified!' if request_types.empty?

  request_types.inject(source_assets_qc_metrics) do |source_assets_qc_metrics_memo, request_type|
    link = ChainLink.build!(request_type, multiplier_for(request_type), source_assets_qc_metrics_memo, self)
    break if preplexed && link.multiplexed?

    link.target_assets_qc_metrics
  end
  @built = true
end

#multiplexing_assetsObject

multiplexing_assets returns @multiplexing_assets if present otherwise it yields to any presented block and assumes it returns the multiplexing_assets



48
49
50
51
52
53
# File 'app/models/submission/flexible_request_graph.rb', line 48

def multiplexing_assets
  @multiplexed = true

  @multiplexing_assets ||= yield if block_given?
  @multiplexing_assets
end