Sha256: 45769c8e347b8af6fdf36b4a6e61cf457c75b08810404f37b3e8281cfe48c011

Contents?: true

Size: 965 Bytes

Versions: 2

Compression:

Stored size: 965 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)
          send :include, ActiveRecord::Acts::ShoppingCart::Collection
          send :include, ActiveRecord::Acts::ShoppingCart::Item
          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

2 entries across 2 versions & 1 rubygems

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