Class: JsonapiCompliable::Util::IncludeParams
- Inherits:
-
Object
- Object
- JsonapiCompliable::Util::IncludeParams
- Defined in:
- lib/jsonapi_compliable/util/include_params.rb
Overview
Utility class for dealing with Include Directives
Class Method Summary collapse
-
.scrub(requested_includes, allowed_includes) ⇒ Hash
Let's say the user requested these sideloads:.
Class Method Details
.scrub(requested_includes, allowed_includes) ⇒ Hash
Let's say the user requested these sideloads:
GET /posts?include=comments.author
But our resource had this code:
sideload_whitelist({ index: [:comments] })
We should drop the 'author' sideload from the request.
Hashes become 'include directive hashes' within the library. ie
[:tags, { comments: :author }]
Becomes
{ tags: {}, comments: { author: {} } }
27 28 29 30 31 32 33 34 35 |
# File 'lib/jsonapi_compliable/util/include_params.rb', line 27 def scrub(requested_includes, allowed_includes) {}.tap do |valid| requested_includes.each_pair do |key, sub_hash| if allowed_includes[key] valid[key] = scrub(sub_hash, allowed_includes[key]) end end end end |