Module: Asset::Stock::CanCreateStockAsset

Included in:
LibraryTube, MultiplexedLibraryTube
Defined in:
app/models/asset/stock.rb

Overview

Extending this module will allow an asset to have a stock asset and be able to create it.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/asset/stock.rb', line 5

def self.extended(base)
  base.class_eval do
    stock_asset_type_name = stock_asset_type.name
    has_one_as_child(:stock_asset, ->() { where(sti_type: stock_asset_type_name) })

    def create_stock_asset!(attributes = {}, &block)
      self.class.stock_asset_purpose.create!(attributes.reverse_merge(
                                               name: "(s) #{name}",
                                               aliquots: aliquots.map(&:dup)
                                             ), &block)
    end

    def new_stock_asset(attributes = {}, &block)
      self.class.stock_asset_type.new(attributes.reverse_merge(
                                        name: "(s) #{name}",
                                        aliquots: aliquots.map(&:dup),
                                        purpose: self.class.stock_asset_purpose
                                      ), &block)
    end

    delegate :is_a_stock_asset?, to: 'self.class'
  end
end

Instance Method Details

#is_a_stock_asset?Boolean

By being able to create a stock asset the asset itself is not a stock.


30
31
32
# File 'app/models/asset/stock.rb', line 30

def is_a_stock_asset?
  false
end