Skip to content

Commit

Permalink
Merge 42b4f18 into 731528e
Browse files Browse the repository at this point in the history
  • Loading branch information
guenin committed May 21, 2013
2 parents 731528e + 42b4f18 commit 28eff26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,10 @@ def as_json(options={})
# Returns a hash representation of the serializable
# object without the root.
def serializable_hash
if perform_caching?
cache.fetch expand_cache_key([self.class.to_s.underscore, cache_key, 'serializable-hash']) do
_serializable_hash
end
else
_serializable_hash
end
return nil if @object.nil?
@node = attributes
include_associations! if _embed
@node
end

def include_associations!
Expand Down Expand Up @@ -451,6 +448,16 @@ def merge_association(hash, key, serializables, unique_values)
# Returns a hash representation of the serializable
# object attributes.
def attributes
if perform_caching?
cache.fetch expand_cache_key([self.class.to_s.underscore, cache_key, 'attributes']) do
_serializable_attributes
end
else
_serializable_attributes
end
end

def _serializable_attributes
_fast_attributes
rescue NameError
method = "def _fast_attributes\n"
Expand All @@ -473,13 +480,6 @@ def scope

alias :read_attribute_for_serialization :send

def _serializable_hash
return nil if @object.nil?
@node = attributes
include_associations! if _embed
@node
end

def perform_caching?
perform_caching && cache && respond_to?(:cache_key)
end
Expand Down
2 changes: 1 addition & 1 deletion test/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def cache_key

instance.to_json

assert_equal(instance.serializable_hash, serializer.cache.read('serializer/Adam/serializable-hash'))
assert_equal(instance.attributes, serializer.cache.read('serializer/Adam/attributes'))
assert_equal(instance.to_json, serializer.cache.read('serializer/Adam/to-json'))
end

Expand Down

0 comments on commit 28eff26

Please sign in to comment.