Class: Toller::Filters::WhereHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/toller/filters/where_handler.rb

Overview

Where handler for filter

Instance Method Summary collapse

Instance Method Details

#call(collection, type, value, properties) ⇒ ActiveRecord::Relation

Applies a plain where clause to collection for a non-scope filter.

Parameters:

  • collection (ActiveRecord::Relation)

    the collection to filter

  • type (Symbol)

    the filter type (e.g. :string, :integer, :boolean)

  • value (Object)

    the raw filter param value

  • properties (Hash)

    the filter's properties, used to resolve :field

Returns:

  • (ActiveRecord::Relation)

    the filtered collection



17
18
19
20
21
22
23
# File 'lib/toller/filters/where_handler.rb', line 17

def call(collection, type, value, properties)
  field_name = properties[:field]

  mutated_value = value_mutator(type, value)

  collection.where(field_name => mutated_value)
end