Sha256: 1c863fc95e63203d48874610aefbcc54cc44ae0f1bf54930b2d66b7a35da86e6

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

##
# As Source Product 是产品关联的源产品的领域逻辑关注点。

module Unidom::Product::Concerns::AsSourceProduct

  extend  ActiveSupport::Concern
  include Unidom::Common::Concerns::ArgumentValidation

  included do |includer|

    has_many :target_product_associatings, class_name: 'Unidom::Product::ProductAssociating', foreign_key: :source_id
    has_many :target_products,             through:    :target_product_associatings,          source: :target

    def associate!(target, due_to: nil, at: Time.now, ordinal: 1)

      assert_present! :target,  target
      assert_present! :due_to,  due_to
      assert_present! :at,      at
      assert_present! :ordinal, ordinal

      target_product_associatings.target_is(target).product_association_coded_as(due_to).valid_at(now: at).alive.first_or_create! ordinal: ordinal, opened_at: at

    end

    def associate?(target, due_to: nil, at: Time.now)

      assert_present! :target, target
      assert_present! :due_to, due_to
      assert_present! :at,     at

      target_product_associatings.target_is(target).product_association_coded_as(due_to).valid_at(now: at).alive.exists?

    end

  end

  module ClassMethods
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unidom-product-2.0 app/models/unidom/product/concerns/as_source_product.rb
unidom-product-1.7.8 app/models/unidom/product/concerns/as_source_product.rb