Skip to content

Commit

Permalink
rename add_relationship methods to be less awkward
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 1, 2015
1 parent 081b504 commit f05cf96
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/active_model/serializer/adapter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,22 +36,22 @@ 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

@hash
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

Expand Down

0 comments on commit f05cf96

Please sign in to comment.