Sha256: 9d25e659f870975f04d24824fb8399f2a97865a7475d700107685d1559ad5e5f

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

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

      module ClassMethods
        #
        # Prepares the class to act as a cart.
        #
        # Receives as a parameter the name of the class that will hold the items
        #
        # Example:
        #
        #   acts_as_shopping_cart :cart_item
        #
        #
        def acts_as_shopping_cart_using(item_class)
          self.send :include, ActiveRecord::Acts::ShoppingCart::Cart::InstanceMethods
          self.send :include, ActiveRecord::Acts::ShoppingCart::Item::InstanceMethods
          has_many :shopping_cart_items, :class_name => item_class.to_s.classify,
              :as => :owner, :dependent => :destroy
        end

        #
        # Alias for:
        #
        #    acts_as_shopping_cart_using :shopping_cart_item
        #
        def acts_as_shopping_cart
          acts_as_shopping_cart_using :shopping_cart_item
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.1.6 lib/active_record/acts/shopping_cart.rb
acts_as_shopping_cart-0.1.5 lib/active_record/acts/shopping_cart.rb
acts_as_shopping_cart-0.1.4 lib/active_record/acts/shopping_cart.rb
acts_as_shopping_cart-0.1.3 lib/active_record/acts/shopping_cart.rb