Class: JsonapiCompliable::Scope::Filter

Inherits:
Scope::Base
  • Object
show all
Includes:
Filterable
Defined in:
lib/jsonapi_compliable/scope/filter.rb

Instance Method Summary collapse

Methods included from Filterable

#filter_param, #find_filter, #find_filter!

Instance Method Details

#applyObject



5
6
7
8
9
10
11
# File 'lib/jsonapi_compliable/scope/filter.rb', line 5

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

  @scope
end

#filter_scope(filter, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jsonapi_compliable/scope/filter.rb', line 13

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