Sha256: 61524c3108f31d47a8ade19380fd38cdeeb9d569b1e7b57c71737d27864df6d1

Contents?: true

Size: 1.18 KB

Versions: 140

Compression:

Stored size: 1.18 KB

Contents

module Graphiti
  module Util
    # Utility class for dealing with Include Directives
    class IncludeParams
      class << self
        # Let's say the user requested these sideloads:
        #
        #   GET /posts?include=comments.author
        #
        # But our resource had this code:
        #
        #   sideload_allowlist({ 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: {} } }
        #
        # @param [Hash] requested_includes the nested hash the user requested
        # @param [Hash] allowed_includes the nested hash configured via DSL
        # @return [Hash] the scrubbed hash
        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
      end
    end
  end
end

Version data entries

140 entries across 140 versions & 1 rubygems

Version Path
graphiti-1.7.6 lib/graphiti/util/include_params.rb
graphiti-1.7.5 lib/graphiti/util/include_params.rb
graphiti-1.7.4 lib/graphiti/util/include_params.rb
graphiti-1.7.3 lib/graphiti/util/include_params.rb
graphiti-1.7.2 lib/graphiti/util/include_params.rb
graphiti-1.7.1 lib/graphiti/util/include_params.rb
graphiti-1.7.0 lib/graphiti/util/include_params.rb
graphiti-1.6.4 lib/graphiti/util/include_params.rb
graphiti-1.6.3 lib/graphiti/util/include_params.rb
graphiti-1.6.2 lib/graphiti/util/include_params.rb
graphiti-1.6.1 lib/graphiti/util/include_params.rb
graphiti-1.6.0 lib/graphiti/util/include_params.rb
graphiti-1.5.3 lib/graphiti/util/include_params.rb
graphiti-1.5.2 lib/graphiti/util/include_params.rb
graphiti-1.5.1 lib/graphiti/util/include_params.rb
graphiti-1.5.0 lib/graphiti/util/include_params.rb
graphiti-1.4.0 lib/graphiti/util/include_params.rb
graphiti-1.3.9 lib/graphiti/util/include_params.rb
graphiti-1.3.8 lib/graphiti/util/include_params.rb
graphiti-1.3.7 lib/graphiti/util/include_params.rb