Sha256: 6282e2968f89a85658ed30c7d6c37fdd8661604f115244dd1f6b7a95c8ad8ee8

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

module ActiveRecord
  module Acts
    module ShoppingCartItem
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        #
        # Prepares the class to act as a cart item.
        #
        # Receives as a parameter the name of the class that acts as a cart
        #
        # Example:
        #
        #   acts_as_shopping_cart_item :cart
        #
        #
        def acts_as_shopping_cart_item_for(*)
          send :include, ActiveRecord::Acts::ShoppingCartItem::InstanceMethods
          belongs_to :owner, polymorphic: true
          belongs_to :item, polymorphic: true
          monetize :price_cents
        end

        #
        # Alias for:
        #
        #   acts_as_shopping_cart_item_for :shopping_cart
        #
        def acts_as_shopping_cart_item
          acts_as_shopping_cart_item_for :shopping_cart
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.4.1 lib/active_record/acts/shopping_cart_item.rb
acts_as_shopping_cart-0.4.0 lib/active_record/acts/shopping_cart_item.rb