Module: JSONAPI::ResourceActions::Serialization
- Extended by:
- ActiveSupport::Concern
- Includes:
- IncludePreloading
- Defined in:
- lib/json_api/controllers/concerns/resource_actions/serialization.rb
Instance Method Summary collapse
- #serialize_collection(resources) ⇒ Object
- #serialize_resource(resource) ⇒ Object
- #serialize_resource_with_sidepost(resource, sideposted_records) ⇒ Object
Instance Method Details
#serialize_collection(resources) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/json_api/controllers/concerns/resource_actions/serialization.rb', line 30 def serialize_collection(resources) includes = parse_include_param fields = parse_fields_param resources = scope_with_includes(resources) resources_array = resources.to_a preload_included_resource_associations(resources_array, includes) data, all_included = serialize_resources_with_includes(resources_array, includes, fields) build_collection_response(data, all_included) end |
#serialize_resource(resource) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/json_api/controllers/concerns/resource_actions/serialization.rb', line 9 def serialize_resource(resource) JSONAPI::Serializer.new(resource).to_hash( include: parse_include_param, fields: parse_fields_param, document_meta: , ) end |
#serialize_resource_with_sidepost(resource, sideposted_records) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/json_api/controllers/concerns/resource_actions/serialization.rb', line 17 def serialize_resource_with_sidepost(resource, sideposted_records) result = serialize_resource(resource) return result if sideposted_records.empty? fields = parse_fields_param sideposted_objects = sideposted_records.map do |rec| JSONAPI::Serializer.new(rec).to_hash(include: [], fields:, document_meta: nil)[:data] end all_included = (result[:included] || []) + sideposted_objects result[:included] = deduplicate_included(all_included) result end |