Sha256: 43c69d29708d4dc6d2301b2435b2f9bd45f39adcfd5308e268683bc0793f6895
Contents?: true
Size: 1.05 KB
Versions: 11
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module Shark module RSpec module Helpers module CacheHelper def find(type, id) objects.detect { |o| o['type'] == type && o['id'] == id } end def included_resources(object_or_objects, params) return [] unless params['include'].present? relationships = params['include'].split(',') included_objects = [] to_array(object_or_objects).each do |object| relationships.each do |name| rdata = object.dig('relationships', name, 'data') to_array(rdata).each do |r| included_objects << find(r['type'], r['id']) end end end included_objects.compact end private def to_array(object_or_objects) case object_or_objects when Hash [object_or_objects] when Array object_or_objects else Array(object_or_objects) end end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems