Sha256: 0ab8dde0c336b1426c03a8c7ad6597ba254df94b3cf58cf07d15952bfa9499c3

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

# Mostly for the callbacks

module ActsAsPurchasableParent
  extend ActiveSupport::Concern

  module Base
    def acts_as_purchasable_parent(*options)
      @acts_as_purchasable_parent = options || []
      include ::ActsAsPurchasableParent
    end
  end

  module ClassMethods
    def acts_as_purchasable_parent?; true; end

    def before_defer(&block)
      send :define_method, :before_defer do |order| self.instance_exec(order, &block) end
    end

    def after_defer(&block)
      send :define_method, :after_defer do |order| self.instance_exec(order, &block) end
    end

    def before_purchase(&block)
      send :define_method, :before_purchase do |order| self.instance_exec(order, &block) end
    end

    def after_purchase(&block)
      send :define_method, :after_purchase do |order| self.instance_exec(order, &block) end
    end

    def before_decline(&block)
      send :define_method, :before_decline do |order| self.instance_exec(order, &block) end
    end

    def after_decline(&block)
      send :define_method, :after_decline do |order| self.instance_exec(order, &block) end
    end
  end

  included do
    has_many :orders, -> { order(:id) }, as: :parent, class_name: 'Effective::Order', dependent: :nullify
    accepts_nested_attributes_for :orders
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
effective_orders-6.12.3 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.12.2 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.12.1 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.12.0 app/models/concerns/acts_as_purchasable_parent.rb