Sha256: 66d6cabd48cea472a27ab17d253c18b9f95dbdc5d5457a335dc3e0252e9cc394
Contents?: true
Size: 761 Bytes
Versions: 5
Compression:
Stored size: 761 Bytes
Contents
require 'json_api_client/included_data' module FlexCommerceApi module JsonApiClientExtension class IncludedData < ::JsonApiClient::IncludedData def initialize(result_set, *args) super(result_set, *args) @result_set = result_set end private # attempt to load the record from included data first, failing that, look # in the root resource(s) for the record def record_for(link_def) data.dig(link_def["type"], link_def["id"]) || root_record_for(link_def) end def root_record_for(link_def) @result_set.find do |resource| resource.attributes["type"] == link_def["type"] && resource.attributes["id"] == link_def["id"] end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems