Module: Jsonapi::Filter::ClassMethods

Defined in:
lib/jsonapi/scopes/filters.rb

Instance Method Summary collapse

Instance Method Details

#apply_filter(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jsonapi/scopes/filters.rb', line 17

def apply_filter(params)
  records = all
  filtering_params = params.dig(:filter) || {}

  filtering_params.each do |key, value|
    value = value.to_s.split(',').reject(&:blank?) if value.include?(',')

    records = records.public_send(key, value) if @filters.include?(key.to_sym)
  end

  records
end

#filter(name, *args) ⇒ Object



12
13
14
15
# File 'lib/jsonapi/scopes/filters.rb', line 12

def filter(name, *args)
  scope(name, *args)
  @filters << name
end