shop_bunny 0.7.4.19 → 0.7.4.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ class CartItem < ActiveRecord::Base
19
19
  end
20
20
 
21
21
  def item=(new_item)
22
- write_attribute(:raw_item, new_item.to_json)
22
+ write_attribute(:raw_item, new_item.shop_bunny_json_attributes.to_json)
23
23
  @parsed_raw_item = nil
24
24
  new_item
25
25
  end
@@ -28,7 +28,6 @@ class CartItem < ActiveRecord::Base
28
28
  return nil unless raw_item
29
29
  unless @parsed_raw_item
30
30
  json = JSON.parse(raw_item)
31
- json = json.values.first if json.kind_of?(Hash)
32
31
 
33
32
  if json
34
33
  @parsed_raw_item = ShopBunny.item_model_class_name.constantize.new(json)
data/app/models/item.rb CHANGED
@@ -2,5 +2,13 @@
2
2
  class Item < ActiveRecord::Base
3
3
  validates_presence_of :price
4
4
  validates_numericality_of :price
5
+
6
+ # The host app can return a hash here that get's serialized on the
7
+ # CartItems and Items get instanstiated of this hash when CartItem#item is
8
+ # called.
9
+ # The default implementation uses the attributes hash of ActiveRecord
10
+ def shop_bunny_json_attributes
11
+ attributes
12
+ end
5
13
  end
6
14
 
data/lib/shop_bunny.rb CHANGED
@@ -18,28 +18,5 @@ module ShopBunny
18
18
  # initializer which gets generated by `rails generate shop_bunny:install`
19
19
  def self.setup
20
20
  yield self
21
-
22
- item_class = ShopBunny.item_model_class_name.constantize
23
-
24
- unless item_class.method_defined?(:as_json_with_included_id)
25
- item_class.class_eval do
26
- def shop_bunny_json_options(options)
27
- options ||= {}
28
- options[:methods] ||= []
29
- if options[:methods].kind_of?(Array)
30
- options[:methods] += [:id]
31
- else
32
- options[:methods] = [options[:methods], :id]
33
- end
34
- options[:methods].uniq!
35
- options
36
- end
37
-
38
- def as_json_with_included_id(options = {})
39
- as_json_without_included_id(shop_bunny_json_options(options))
40
- end
41
- alias_method_chain :as_json, :included_id
42
- end
43
- end
44
21
  end
45
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shop_bunny
3
3
  version: !ruby/object:Gem::Version
4
- hash: 65
4
+ hash: 79
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 4
10
- - 19
11
- version: 0.7.4.19
10
+ - 20
11
+ version: 0.7.4.20
12
12
  platform: ruby
13
13
  authors:
14
14
  - kopfmaschine.com