From 4bfbdc133a37c6046b8854d3659ba75597d1d37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 23 Sep 2011 00:19:46 +0200 Subject: Refactor AMo as_json. --- activemodel/lib/active_model/serializers/json.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index 3c713311fd..885964633f 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -86,16 +86,12 @@ module ActiveModel # "title": "Welcome to the weblog"}, # {"comments": [{"body": "Don't think too hard"}], # "title": "So I was thinking"}]} - def as_json(options = nil) - opts_root = options[:root] if options.try(:key?, :root) - if opts_root - custom_root = opts_root == true ? self.class.model_name.element : opts_root - { custom_root => serializable_hash(options) } - elsif opts_root == false - serializable_hash(options) - elsif include_root_in_json - { self.class.model_name.element => serializable_hash(options) } + root = include_root_in_json + root = options[:root] if options.try(:key?, :root) + if root + root = self.class.model_name.element if root == true + { root => serializable_hash(options) } else serializable_hash(options) end -- cgit v1.2.3