active_cart 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,27 @@ In this example the ShippingOrderTotal and GstOrderTotal have been created by th
19
19
 
20
20
  For information about the API and interfase, checkout the documentation: http://rdoc.info/projects/madpilot/active_cart
21
21
 
22
- == Todo
23
-
24
- Write some actual Storage Engines and OrderTotal examples.
22
+ == Sample using the contrived Memory demo classes in irb
23
+
24
+ >> require 'rubygems'
25
+ => true
26
+ >> require 'active_cart'
27
+ => true
28
+ >> include ActiveCart
29
+ => Object
30
+ >> c = Cart.new(ActiveCart::StorageEngines::Memory.new)
31
+ => #<ActiveCart::Cart:0xb7a697a0 @order_total_calculators=[], @storage_engine=[]>
32
+ >> c.add_to_cart(ActiveCart::Items::MemoryItem.new(1, "Test Item", 10))
33
+ => nil
34
+ >> c.add_to_cart(ActiveCart::Items::MemoryItem.new(1, "Test Item", 10))
35
+ => nil
36
+ >> c[0]
37
+ => #<ActiveCart::Items::MemoryItem:0xb7a63170 @price=10, @name="Test Item", @quantity=2, @id=1>
38
+ >> c.total
39
+ => 20
40
+
41
+ == TODO
42
+
43
+ Write an ActiveMerchant acts_as_ plugin. Write an interface to MondoDB or CouchDB (or both). Write a reference rails engine that implements a working shopping cart site
25
44
 
26
45
  Copyright (c) 2010 Myles Eftos (myles@madpilot.com.au), released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -4,11 +4,14 @@ require 'rubygems'
4
4
  require 'singleton'
5
5
  require 'forwardable'
6
6
  require 'aasm'
7
- require 'active_cart/item'
8
- require 'active_cart/cart_storage'
9
- require 'active_cart/order_total'
10
- require 'active_cart/order_total_collection'
11
- require 'active_cart/cart'
7
+ require 'item'
8
+ require 'cart_storage'
9
+ require 'order_total'
10
+ require 'order_total_collection'
11
+ require 'cart'
12
+
13
+ require 'storage_engines/memory'
14
+ require 'items/memory_item'
12
15
 
13
16
  module ActiveCart
14
17
  VERSION = File.exist?('VERSION') ? File.read('VERSION') : ""
@@ -104,27 +104,6 @@ module ActiveCart
104
104
  inject(0) { |t, item| t + item.quantity }
105
105
  end
106
106
 
107
- # Returns the unique invoice_id for this cart instance. This MUST be overriden by the concrete class this module is mixed into, otherwise you
108
- # will get a NotImplementedError
109
- #
110
- def invoice_id
111
- raise NotImplementedError
112
- end
113
-
114
- # Returns the sub-total of all the items in the cart. Usually returns a float.
115
- #
116
- # @cart.sub_total # => 100.00
117
- #
118
- def sub_total
119
- inject(0) { |t, item| t + (item.quantity * item.price) }
120
- end
121
-
122
- # Returns the number of items in the cart. It takes into account the individual quantities of each item, eg if there are 3 items in the cart, each with a quantity of 2, this will return 6
123
- #
124
- def quantity
125
- inject(0) { |t, item| t + item.quantity }
126
- end
127
-
128
107
  # Adds an item to the cart. If the item already exists in the cart (identified by the id of the item), then the quantity will be increased but the supplied quantity (default: 1)
129
108
  #
130
109
  # @cart.add_to_cart(item, 5)
@@ -0,0 +1,18 @@
1
+ module ActiveCart
2
+ module Items
3
+ class MemoryItem
4
+ attr_accessor :id, :name, :price
5
+ include ActiveCart::Item
6
+
7
+ def ==(item)
8
+ self.id == item.id
9
+ end
10
+
11
+ def initialize(id, name, price)
12
+ @id = id
13
+ @name = name
14
+ @price = price
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveCart
2
+ module StorageEngines
3
+ # This storage engine is probably only useful as a reference implementation (It would work in a desktop app I guess). Items only exist in memory, so
4
+ # as soon as the thread dies, so does the cart.
5
+ #
6
+ class Memory < Array
7
+ include ActiveCart::CartStorage
8
+
9
+ def invoice_id
10
+ @@last_id = @@last_id ? @@last_id + 1 : 1
11
+ end
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myles Eftos
@@ -70,8 +70,10 @@ files:
70
70
  - lib/active_cart/cart.rb
71
71
  - lib/active_cart/cart_storage.rb
72
72
  - lib/active_cart/item.rb
73
+ - lib/active_cart/items/memory_item.rb
73
74
  - lib/active_cart/order_total.rb
74
75
  - lib/active_cart/order_total_collection.rb
76
+ - lib/active_cart/storage_engines/memory.rb
75
77
  - test/mocks/test_cart_storage.rb
76
78
  - test/mocks/test_item.rb
77
79
  - test/mocks/test_order_total.rb