Permalink
Browse files

Revert "Merge branch 'master' of github.com:Shopify/shopify_api"

This reverts commit 855fe5d, reversing
changes made to cbe5b16.
  • Loading branch information...
1 parent 855fe5d commit 0769cdd5ec62e295c6dc5e700ded872bc4f856c4 @garethson garethson committed Oct 5, 2012
Showing with 34 additions and 25 deletions.
  1. +34 −11 lib/shopify_api/json_format.rb
  2. +0 −14 lib/shopify_api/resources/base.rb
@@ -1,16 +1,39 @@
module ActiveResource
- if ActiveResource::VERSION::STRING =~ /^3\.0\./
- module Formats
- module JsonFormat
- def decode(json)
- data = ActiveSupport::JSON.decode(json)
- if data.is_a?(Hash) && data.keys.size == 1
- data.values.first
- else
- data
- end
+ class Base
+ def encode(options = {})
+ same = dup
+ same.attributes = {self.class.element_name => same.attributes} if self.class.format.extension == 'json'
+
+ same.send("to_#{self.class.format.extension}", options)
+ end
+ end
+
+ module Formats
+ module JsonFormat
+ def decode(json)
+ data = ActiveSupport::JSON.decode(json)
+ if data.is_a?(Hash) && data.keys.size == 1
+ data.values.first
+ else
+ data
+ end
+ end
+ end
+ end
+end
+
+module ActiveModel
+ module Serializers
+ module JSON
+ def as_json(options = nil)
+ root = options[:root] if options.try(:key?, :root)
+ if include_root_in_json
+ root = self.class.model_name.element if root == true
+ { root => serializable_hash(options) }
+ else
+ serializable_hash(options)
end
end
end
end
-end
+end
@@ -34,23 +34,9 @@ def persisted?
!id.nil?
end
- def encode(options = {})
- obj = dup
-
- if self.class.format.extension == 'json' && !already_has_root_element?(obj.attributes)
- obj.attributes = {self.class.element_name => obj.attributes}
- end
-
- obj.send("to_#{self.class.format.extension}", options)
- end
private
def only_id
encode(:only => :id, :include => [], :methods => [])
end
-
- def already_has_root_element?(attributes)
- attributes.keys.size == 1 && attributes.values.first.kind_of?(Hash)
- end
end
end
-

0 comments on commit 0769cdd

Please sign in to comment.