cart 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/cart.gemspec +3 -3
- data/lib/cart/advanced.rb +14 -14
- data/lib/cart/config.rb +2 -0
- data/lib/cart/logger_stub.rb +2 -0
- data/lib/cart/simple.rb +2 -0
- metadata +3 -3
data/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
/*.gem
|
data/cart.gemspec
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require "base64"
|
4
4
|
|
5
|
-
|
5
|
+
Gem::Specification.new do |s|
|
6
6
|
s.name = "cart"
|
7
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.3"
|
8
8
|
s.authors = ["Jakub Šťastný aka Botanicus"]
|
9
9
|
s.homepage = "http://github.com/botanicus/cart"
|
10
10
|
s.summary = "Cart is framework agnostic solution for shopping cart."
|
@@ -15,5 +15,5 @@ SPECIFICATION = ::Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
# s.required_ruby_version = ::Gem::Requirement.new(">= 1.9.1")
|
18
|
-
|
18
|
+
s.rubyforge_project = "cart"
|
19
19
|
end
|
data/lib/cart/advanced.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "cart/config"
|
2
4
|
|
3
5
|
class Cart
|
@@ -47,23 +49,23 @@ class Cart
|
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
def items_equal?(
|
52
|
+
def items_equal?(one, other)
|
51
53
|
# this is important, we must compare all the properties exclude count
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
properties
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
block = Proc.new { |item| item.count = 1 }
|
55
|
+
one.tap(&block) == other.tap(&block)
|
56
|
+
|
57
|
+
# # from form empty values goes as "", but deserialized empty items are nil
|
58
|
+
# properties = new.class.properties.map(&:name)
|
59
|
+
# properties.each do |property|
|
60
|
+
# value = new.send(property)
|
61
|
+
# new.send("#{property}=", nil) if value.respond_to?(:empty?) && value.empty?
|
62
|
+
# end
|
63
|
+
# new.eql?(old)
|
61
64
|
end
|
62
65
|
|
63
66
|
def remove(params)
|
64
67
|
raise ArgumentError unless params.is_a?(Hash)
|
65
68
|
item_to_remove = @config.metadata_model.new(params)
|
66
|
-
p [item_to_remove], @items ####
|
67
69
|
pre = @items.dup
|
68
70
|
@items.delete_if { |item| items_equal?(item, item_to_remove) }
|
69
71
|
removed = pre - @items
|
@@ -93,9 +95,7 @@ class Cart
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def each(&block)
|
96
|
-
@items.each
|
97
|
-
block.call(item)
|
98
|
-
end
|
98
|
+
@items.each(&block)
|
99
99
|
end
|
100
100
|
|
101
101
|
def empty?
|
data/lib/cart/config.rb
CHANGED
data/lib/cart/logger_stub.rb
CHANGED
data/lib/cart/simple.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
|
-
date: 2010-02-
|
11
|
+
date: 2010-02-23 00:00:00 +00:00
|
12
12
|
default_executable:
|
13
13
|
dependencies: []
|
14
14
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version:
|
62
62
|
requirements: []
|
63
63
|
|
64
|
-
rubyforge_project:
|
64
|
+
rubyforge_project: cart
|
65
65
|
rubygems_version: 1.3.5
|
66
66
|
signing_key:
|
67
67
|
specification_version: 3
|