Class: ActiveModel::Serializer::Adapter::Json
- Inherits:
-
ActiveModel::Serializer::Adapter
- Object
- ActiveModel::Serializer::Adapter
- ActiveModel::Serializer::Adapter::Json
- Defined in:
- lib/active_model/serializer/adapter/json.rb,
lib/active_model/serializer/adapter/json/fragment_cache.rb
Direct Known Subclasses
Defined Under Namespace
Classes: FragmentCache
Instance Attribute Summary
Attributes inherited from ActiveModel::Serializer::Adapter
Instance Method Summary collapse
Methods inherited from ActiveModel::Serializer::Adapter
adapter_class, #as_json, create, #initialize
Constructor Details
This class inherits a constructor from ActiveModel::Serializer::Adapter
Instance Method Details
#fragment_cache(cached_hash, non_cached_hash) ⇒ Object
46 47 48 |
# File 'lib/active_model/serializer/adapter/json.rb', line 46 def fragment_cache(cached_hash, non_cached_hash) Json::FragmentCache.new().fragment_cache(cached_hash, non_cached_hash) end |
#serializable_hash(options = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_model/serializer/adapter/json.rb', line 7 def serializable_hash( = nil) ||= {} if serializer.respond_to?(:each) @result = serializer.map { |s| FlattenJson.new(s).serializable_hash() } else @hash = {} @core = cache_check(serializer) do serializer.attributes() end serializer.associations.each do |association| serializer = association.serializer opts = association. if serializer.respond_to?(:each) array_serializer = serializer @hash[association.key] = array_serializer.map do |item| cache_check(item) do item.attributes(opts) end end else @hash[association.key] = if serializer && serializer.object cache_check(serializer) do serializer.attributes() end elsif opts[:virtual_value] opts[:virtual_value] end end end @result = @core.merge @hash end { root => @result } end |