Sha256: 0368298569716222af8358a27a86da6ee378e555dfd81fb790c2d06094dff66b

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

module JsonapiCompliable
  class Scoping::ExtraAttributes < Scoping::Base
    # Loop through all requested extra fields. If custom scoping
    # logic is define for that field, run it. Otherwise, do nothing.
    #
    # @return the scope object we are chaining/modofying
    def apply
      each_extra_attribute do |callable|
        @scope = callable.call(@scope, resource.context)
      end

      @scope
    end

    private

    def each_extra_field
      resource.extra_fields.each_pair do |name, callable|
        if extra_fields.include?(name)
          yield callable
        end
      end
    end

    def extra_fields
      query_hash[:extra_fields][resource.type] || []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapi_compliable-1.0.alpha.2 lib/jsonapi_compliable/scoping/extra_attributes.rb