Skip to content

Commit 4bfbdc1

Browse files
committed
Refactor AMo as_json.
1 parent c19c555 commit 4bfbdc1

File tree

1 file changed

+5
-9
lines changed
  • activemodel/lib/active_model/serializers

1 file changed

+5
-9
lines changed

activemodel/lib/active_model/serializers/json.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ module JSON
8686
# "title": "Welcome to the weblog"},
8787
# {"comments": [{"body": "Don't think too hard"}],
8888
# "title": "So I was thinking"}]}
89-
9089
def as_json(options = nil)
91-
opts_root = options[:root] if options.try(:key?, :root)
92-
if opts_root
93-
custom_root = opts_root == true ? self.class.model_name.element : opts_root
94-
{ custom_root => serializable_hash(options) }
95-
elsif opts_root == false
96-
serializable_hash(options)
97-
elsif include_root_in_json
98-
{ self.class.model_name.element => serializable_hash(options) }
90+
root = include_root_in_json
91+
root = options[:root] if options.try(:key?, :root)
92+
if root
93+
root = self.class.model_name.element if root == true
94+
{ root => serializable_hash(options) }
9995
else
10096
serializable_hash(options)
10197
end

0 commit comments

Comments
 (0)