Sha256: e4d333e06eaca6f4007b7037f9f8f1013d69b5d96399351d978a446aa8af7352

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

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
        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

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.1.2 lib/active_record/acts/shopping_cart.rb
acts_as_shopping_cart-0.1.1 lib/active_record/acts/shopping_cart.rb