Sha256: 3f8712407b77546eb4f7fb0315a847b81f8bcba5ae201f5a81868670f29a9a63

Contents?: true

Size: 1.46 KB

Versions: 28

Compression:

Stored size: 1.46 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'

    accepts_nested_attributes_for :orders

    before_destroy do
      orders.each do |order|
        raise('unable to destroy a purchasable_parent with purchased orders') if order.purchased?
        order.voided? ? order.save! : order.void!
      end

      true
    end

  end

end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
effective_orders-6.19.1 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.19.0 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.18.4 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.18.3 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.18.2 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.18.1 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.18.0 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.17.2 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.17.1 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.17.0 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.16.4 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.16.3 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.16.2 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.16.1 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.16.0 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.15.0 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.14.6 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.14.5 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.14.4 app/models/concerns/acts_as_purchasable_parent.rb
effective_orders-6.14.3 app/models/concerns/acts_as_purchasable_parent.rb