Class: Toller::Filters::ScopeHandler

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

Overview

Scope handler for filter

Instance Method Summary collapse

Instance Method Details

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

Applies a named scope to collection for a type: :scope filter.

Parameters:

  • collection (ActiveRecord::Relation)

    the collection to filter

  • value (Object)

    the filter param value to pass to the scope

  • properties (Hash)

    the filter's properties, used to resolve :scope_name (falling back to :field)

Returns:

  • (ActiveRecord::Relation)

    the scoped collection



16
17
18
19
20
# File 'lib/toller/filters/scope_handler.rb', line 16

def call(collection, value, properties)
  scoped_name = properties[:scope_name] || properties[:field]

  collection.public_send(scoped_name, value)
end