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


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

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


13
14
15
# File 'app/models/submission/flexible_request_graph.rb', line 13

def built
  @built
end

#multiplexedObject (readonly) Also known as: multiplexed?

Returns the value of attribute multiplexed


13
14
15
# File 'app/models/submission/flexible_request_graph.rb', line 13

def multiplexed
  @multiplexed
end

#orderObject (readonly)

Returns the value of attribute order


13
14
15
# File 'app/models/submission/flexible_request_graph.rb', line 13

def order
  @order
end

#preplexedObject (readonly) Also known as: preplexed?

Returns the value of attribute preplexed


13
14
15
# File 'app/models/submission/flexible_request_graph.rb', line 13

def preplexed
  @preplexed
end

#source_assets_qc_metricsObject (readonly)

Returns the value of attribute source_assets_qc_metrics


13
14
15
# File 'app/models/submission/flexible_request_graph.rb', line 13

def source_assets_qc_metrics
  @source_assets_qc_metrics
end

Instance Method Details

#build!Object

Raises:


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

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


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

def multiplexing_assets
  @multiplexed = true

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