Class: ActiveModel::Serializer::Adapter::Json
- Inherits:
-
ActiveModel::Serializer::Adapter
- Object
- ActiveModel::Serializer::Adapter
- ActiveModel::Serializer::Adapter::Json
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/active_model/serializer/adapter/json.rb
Direct Known Subclasses
Defined Under Namespace
Classes: FragmentCache
Constant Summary
Constants inherited from ActiveModel::Serializer::Adapter
Instance Attribute Summary
Attributes inherited from ActiveModel::Serializer::Adapter
Instance Method Summary collapse
Methods inherited from ActiveModel::Serializer::Adapter
adapter_class, adapter_map, adapters, #as_json, create, find_by_name, inherited, #initialize, lookup, register
Constructor Details
This class inherits a constructor from ActiveModel::Serializer::Adapter
Instance Method Details
#fragment_cache(cached_hash, non_cached_hash) ⇒ Object
44 45 46 |
# File 'lib/active_model/serializer/adapter/json.rb', line 44 def fragment_cache(cached_hash, non_cached_hash) ActiveModel::Serializer::Adapter::Json::FragmentCache.new().fragment_cache(cached_hash, non_cached_hash) end |
#serializable_hash(options = nil) ⇒ Object
5 6 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 |
# File 'lib/active_model/serializer/adapter/json.rb', line 5 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 |