From f05cf96b0307ef66530348d5ca7dcae70c3be63c Mon Sep 17 00:00:00 2001 From: "L. Preston Sego III" Date: Mon, 31 Aug 2015 20:15:08 -0400 Subject: [PATCH] rename add_relationship methods to be less awkward --- lib/active_model/serializer/adapter/json.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/active_model/serializer/adapter/json.rb b/lib/active_model/serializer/adapter/json.rb index ea873b294..805643c30 100644 --- a/lib/active_model/serializer/adapter/json.rb +++ b/lib/active_model/serializer/adapter/json.rb @@ -6,6 +6,7 @@ class Adapter class Json < Adapter def serializable_hash(options = nil) options ||= {} + if serializer.respond_to?(:each) @result = serialize_array_without_root(serializer, options) else @@ -35,9 +36,9 @@ def add_resource_relationships(serializer) opts = association.options if serializer.respond_to?(:each) - add_relationships(association.key, serializer, opts) + add_has_many_relationship(association.key, serializer, opts) else - add_relationship(association.key, serializer, opts) + add_singular_relationship(association.key, serializer, opts) end end @@ -45,12 +46,12 @@ def add_resource_relationships(serializer) end # add a singular relationship - def add_relationship(key, serializer, options) + def add_singular_relationship(key, serializer, options) @hash[key] = serialized_or_virtual_of(serializer, options) end # add a many relationship - def add_relationships(key, serializer, options) + def add_has_many_relationship(key, serializer, options) @hash[key] = serialize_array(serializer, options) end