carter 0.6.4 → 0.7.0

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.
Files changed (2) hide show
  1. data/lib/carter/controller_additions.rb +48 -3
  2. metadata +21 -21
@@ -6,12 +6,13 @@ module Carter
6
6
  module ClassMethods
7
7
 
8
8
  def has_cart(*args)
9
- ControllerResource.add_before_filter(self, :load_cart, *args)
9
+ has_cart_options = args.extract_options!
10
+ before_filter :load_cart, has_cart_options.slice(:only, :except)
10
11
  include InstanceMethods
11
12
  end
12
13
 
13
14
  def has_cart_for_checkout(*args)
14
- ControllerResource.add_before_filter(self, :load_cart_for_checkout, *args)
15
+ before_filter :load_cart_for_checkout, args.extract_options!.slice(:only, :except)
15
16
  include InstanceMethods
16
17
  end
17
18
 
@@ -21,6 +22,7 @@ module Carter
21
22
  base.extend ClassMethods
22
23
  base.class_attribute :checking_out
23
24
  base.class_attribute :shopping
25
+ base.class_attribute :has_cart_options
24
26
  base.helper_method :cart, :has_cart?, :shopper
25
27
  end
26
28
 
@@ -43,7 +45,7 @@ module Carter
43
45
  end
44
46
 
45
47
  def continue_shopping_or_default_url(default)
46
- session[:continue_shopping_url] || default || root_url
48
+ session[:continue_shopping_url] || default
47
49
  end
48
50
 
49
51
  # to stop the has_cart method called from super class from setting the continue_shopping_url when checking out.
@@ -55,6 +57,49 @@ module Carter
55
57
  shopping == true
56
58
  end
57
59
 
60
+
61
+ def load_cart
62
+ store_shopping_location if self.shopping? && !self.checking_out?
63
+ @cart = load_cart_instance
64
+ @shopper = current_shopper
65
+ end
66
+
67
+ def load_cart_for_checkout
68
+ @cart = load_cart_instance
69
+ @shopper = current_shopper
70
+ end
71
+
72
+ private
73
+
74
+ def load_cart_instance
75
+ find_cart_by_session || find_cart_by_shopper || ::Cart.new
76
+ end
77
+
78
+
79
+ def find_cart_by_shopper
80
+ ::Cart.with_state(default_cart_state).first(:conditions => {:shopper_id => current_shopper.id, :shopper_type => current_shopper.class.name} ) if current_shopper && Carter.settings.persist_by_shopper?
81
+ end
82
+
83
+ def find_cart_by_session
84
+ ::Cart.with_state(default_cart_state).find_by_id(session[:cart_id])
85
+ end
86
+
87
+ def current_shopper
88
+ self.respond_to?(:current_user) ? self.send(:current_user) : nil
89
+ end
90
+
91
+ def store_shopping_location
92
+ session[:continue_shopping_url] = self.request.fullpath
93
+ end
94
+
95
+ def name_from_carter_controller
96
+ params[:controller].sub("Controller", "").underscore.split('/').last.singularize
97
+ end
98
+
99
+ def default_cart_state
100
+ :active
101
+ end
102
+
58
103
  protected
59
104
 
60
105
  def find_cartable(cartable_id=params[:cartable_id])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 4
10
- version: 0.6.4
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Louis Gillies
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-10 00:00:00 Z
18
+ date: 2011-11-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -29,10 +29,10 @@ dependencies:
29
29
  - 3
30
30
  - 0
31
31
  version: 2.3.0
32
- name: rspec
32
+ requirement: *id001
33
33
  prerelease: false
34
+ name: rspec
34
35
  type: :development
35
- requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -45,10 +45,10 @@ dependencies:
45
45
  - 6
46
46
  - 0
47
47
  version: 0.6.0
48
- name: yard
48
+ requirement: *id002
49
49
  prerelease: false
50
+ name: yard
50
51
  type: :development
51
- requirement: *id002
52
52
  - !ruby/object:Gem::Dependency
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -59,10 +59,10 @@ dependencies:
59
59
  segments:
60
60
  - 0
61
61
  version: "0"
62
- name: cucumber
62
+ requirement: *id003
63
63
  prerelease: false
64
+ name: cucumber
64
65
  type: :development
65
- requirement: *id003
66
66
  - !ruby/object:Gem::Dependency
67
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
68
  none: false
@@ -75,10 +75,10 @@ dependencies:
75
75
  - 0
76
76
  - 0
77
77
  version: 1.0.0
78
- name: bundler
78
+ requirement: *id004
79
79
  prerelease: false
80
+ name: bundler
80
81
  type: :development
81
- requirement: *id004
82
82
  - !ruby/object:Gem::Dependency
83
83
  version_requirements: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
@@ -91,10 +91,10 @@ dependencies:
91
91
  - 5
92
92
  - 2
93
93
  version: 1.5.2
94
- name: jeweler
94
+ requirement: *id005
95
95
  prerelease: false
96
+ name: jeweler
96
97
  type: :development
97
- requirement: *id005
98
98
  - !ruby/object:Gem::Dependency
99
99
  version_requirements: &id006 !ruby/object:Gem::Requirement
100
100
  none: false
@@ -105,10 +105,10 @@ dependencies:
105
105
  segments:
106
106
  - 0
107
107
  version: "0"
108
- name: rcov
108
+ requirement: *id006
109
109
  prerelease: false
110
+ name: rcov
110
111
  type: :development
111
- requirement: *id006
112
112
  - !ruby/object:Gem::Dependency
113
113
  version_requirements: &id007 !ruby/object:Gem::Requirement
114
114
  none: false
@@ -121,10 +121,10 @@ dependencies:
121
121
  - 0
122
122
  - 2
123
123
  version: 1.0.2
124
- name: state_machine
124
+ requirement: *id007
125
125
  prerelease: false
126
+ name: state_machine
126
127
  type: :development
127
- requirement: *id007
128
128
  - !ruby/object:Gem::Dependency
129
129
  version_requirements: &id008 !ruby/object:Gem::Requirement
130
130
  none: false
@@ -137,10 +137,10 @@ dependencies:
137
137
  - 1
138
138
  - 5
139
139
  version: 3.1.5
140
- name: money
140
+ requirement: *id008
141
141
  prerelease: false
142
+ name: money
142
143
  type: :development
143
- requirement: *id008
144
144
  description: A really simple shopping cart implementation for rails.
145
145
  email: louisgillies@ygmail.com
146
146
  executables: []