Sha256: 12c53a65991492fc6bdd6cc0b6522e2b930004376ed0cfa357e723410f89ff3d
Contents?: true
Size: 881 Bytes
Versions: 1
Compression:
Stored size: 881 Bytes
Contents
module JSONAPI # Inclusion and sparse fields support module Fetching private # Extracts and formats sparse fieldsets # # Ex.: `GET /resource?fields[relationship]=id,created_at` # # @return [Hash] def jsonapi_fields return {} unless params[:fields].respond_to?(:each_pair) if defined?(ActiveSupport::HashWithIndifferentAccess) extracted = ActiveSupport::HashWithIndifferentAccess.new else extracted = Hash.new end params[:fields].each do |k, v| extracted[k] = v.to_s.split(',').filter_map(&:strip) end extracted end # Extracts and whitelists allowed includes # # Ex.: `GET /resource?include=relationship,relationship.subrelationship` # # @return [Array] def jsonapi_include params['include'].to_s.split(',').filter_map(&:strip) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jsonapi.rb-2.1.1 | lib/jsonapi/fetching.rb |