Sha256: 9060ab48d495861525bf2ab111871de8ee79aa86ae896db59970cb61cb6755c6
Contents?: true
Size: 883 Bytes
Versions: 2
Compression:
Stored size: 883 Bytes
Contents
# frozen_string_literal: true module Dayman class Request module Fields # http://jsonapi.org/format/#fetching-sparse-fieldsets def fields(*selected_fields) Array(selected_fields).flatten.each do |arg| if arg.is_a?(Hash) arg.each do |key, values| fieldsets[key] ||= [] fieldsets[key] += Array(values) end else # TODO: use resource name key = resource.path.to_sym fieldsets[key] ||= [] fieldsets[key].push(arg) end end self end alias select fields private def fieldsets_to_query_parameters return {} if fieldsets.blank? fieldsets.each_with_object({}) do |(key, values), hash| hash["fields[#{key}]"] = values.join(',') end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dayman-0.1.2 | lib/dayman/request/fields.rb |
dayman-0.1.1 | lib/dayman/request/fields.rb |