Module: HttpApiTools::Sideloading::JsonSerializer
- Includes:
- BaseJsonSerializer
- Defined in:
- lib/http_api_tools/sideloading/json_serializer.rb
Instance Attribute Summary collapse
-
#attribute_mappings ⇒ Object
readonly
Returns the value of attribute attribute_mappings.
-
#cached ⇒ Object
readonly
Returns the value of attribute cached.
-
#has_many_mappings ⇒ Object
readonly
Returns the value of attribute has_many_mappings.
-
#has_one_mappings ⇒ Object
readonly
Returns the value of attribute has_one_mappings.
-
#relation_includes ⇒ Object
readonly
Returns the value of attribute relation_includes.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Attributes included from BaseJsonSerializer
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
- #as_sideloaded_hash ⇒ Object
- #initialize(serializable, attrs = {}) ⇒ Object
Methods included from BaseJsonSerializer
#attribute_hash, #attributes, #has_manys, #has_ones, #includable, #includes, #meta, #to_json
Instance Attribute Details
#attribute_mappings ⇒ Object (readonly)
Returns the value of attribute attribute_mappings.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def attribute_mappings @attribute_mappings end |
#cached ⇒ Object (readonly)
Returns the value of attribute cached.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def cached @cached end |
#has_many_mappings ⇒ Object (readonly)
Returns the value of attribute has_many_mappings.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def has_many_mappings @has_many_mappings end |
#has_one_mappings ⇒ Object (readonly)
Returns the value of attribute has_one_mappings.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def has_one_mappings @has_one_mappings end |
#relation_includes ⇒ Object (readonly)
Returns the value of attribute relation_includes.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def relation_includes @relation_includes end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
11 12 13 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 11 def result @result end |
Instance Method Details
#as_json(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 19 def as_json(*args) result[root_key] = [] Array(serializable).each do |serializable_item| serialize_item_and_cache_relationships(serializable_item) end result.merge({ meta: .merge(), linked: relation_sideloader.as_json }) end |
#as_sideloaded_hash ⇒ Object
30 31 32 33 34 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 30 def as_sideloaded_hash hash = attribute_hash.merge(links: has_one_hash.merge(has_many_hash)) relation_sideloader.sideload_relations hash end |
#initialize(serializable, attrs = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/http_api_tools/sideloading/json_serializer.rb', line 13 def initialize(serializable, attrs = {}) super @identity_map = attrs[:identity_map] || IdentityMap.new @type_key_resolver = attrs[:type_key_resolver] || TypeKeyResolver.new end |