Class: Toller::Filters::ScopeHandler
- Inherits:
-
Object
- Object
- Toller::Filters::ScopeHandler
- Defined in:
- lib/toller/filters/scope_handler.rb
Overview
Scope handler for filter
Instance Method Summary collapse
-
#call(collection, value, properties) ⇒ ActiveRecord::Relation
Applies a named scope to
collectionfor atype: :scopefilter.
Instance Method Details
#call(collection, value, properties) ⇒ ActiveRecord::Relation
Applies a named scope to collection for a type: :scope filter.
If the resolved scope doesn't exist on the collection's model, the filter is logged and skipped instead of raising a NoMethodError.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/toller/filters/scope_handler.rb', line 19 def call(collection, value, properties) scoped_name = properties[:scope_name] || properties[:field] unless collection.klass.respond_to?(scoped_name) Rails.logger.warn("[Toller] Skipping filter: #{collection.klass} has no scope `#{scoped_name}`") return collection end collection.public_send(scoped_name, value) end |