cart 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1 @@
1
- pkg/
1
+ /*.gem
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "base64"
4
4
 
5
- SPECIFICATION = ::Gem::Specification.new do |s|
5
+ Gem::Specification.new do |s|
6
6
  s.name = "cart"
7
- s.version = "0.0.2"
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
- # s.rubyforge_project = "cart"
18
+ s.rubyforge_project = "cart"
19
19
  end
@@ -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?(old, new)
52
+ def items_equal?(one, other)
51
53
  # this is important, we must compare all the properties exclude count
52
- old = old.dup.tap { |old| old.count = 1 }
53
- new = new.dup.tap { |new| new.count = 1 }
54
- # from form empty values goes as "", but deserialized empty items are nil
55
- properties = new.class.properties.map(&:name)
56
- properties.each do |property|
57
- value = new.send(property)
58
- new.send("#{property}=", nil) if value.respond_to?(:empty?) && value.empty?
59
- end
60
- new.eql?(old)
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 do |item|
97
- block.call(item)
98
- end
98
+ @items.each(&block)
99
99
  end
100
100
 
101
101
  def empty?
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "cart/logger_stub"
2
4
 
3
5
  class NotInitializedError < StandardError ; end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # This class is just a wrapper which give you
2
4
  # chance to give callable object instead of logger.
3
5
  # See README file for more informations.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "ostruct"
2
4
  require "cart/config"
3
5
 
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.2
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-22 00:00:00 +00:00
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