Sha256: b6f7a014de6887dc0d21b62a05bd9b573e61b4107556a65ea0772e93099e2469

Contents?: true

Size: 758 Bytes

Versions: 12

Compression:

Stored size: 758 Bytes

Contents

module JsonapiCompliable
  class Scoping::Filter < Scoping::Base
    include Scoping::Filterable

    def apply
      each_filter do |filter, value|
        @scope = filter_scope(filter, value)
      end

      @scope
    end

    def filter_scope(filter, value)
      if custom_scope = filter.values.first[:filter]
        custom_scope.call(@scope, value)
      else
        resource.adapter.filter(@scope, filter.keys.first, value)
      end
    end

    private

    def each_filter
      filter_param.each_pair do |param_name, param_value|
        filter = find_filter!(param_name.to_sym)
        value  = param_value
        value  = value.split(',') if value.is_a?(String) && value.include?(',')
        yield filter, value
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jsonapi_compliable-0.6.4 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.6.3 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.6.2 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.6.1 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.6.0 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.7 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.6 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.5 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.4 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.3 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.2 lib/jsonapi_compliable/scoping/filter.rb
jsonapi_compliable-0.5.1 lib/jsonapi_compliable/scoping/filter.rb