Class: Filterameter::Filters::ConditionalScopeFilter
- Inherits:
-
Object
- Object
- Filterameter::Filters::ConditionalScopeFilter
- Includes:
- Errors
- Defined in:
- lib/filterameter/filters/conditional_scope_filter.rb
Overview
# Conditional Scope Filter
Class ConditionalScopeFilter applies the scope if the parameter is not false.
Instance Attribute Summary
Attributes included from Errors
Instance Method Summary collapse
- #apply(query, value) ⇒ Object
-
#initialize(scope_name) ⇒ ConditionalScopeFilter
constructor
A new instance of ConditionalScopeFilter.
Methods included from Errors
Constructor Details
#initialize(scope_name) ⇒ ConditionalScopeFilter
Returns a new instance of ConditionalScopeFilter.
11 12 13 |
# File 'lib/filterameter/filters/conditional_scope_filter.rb', line 11 def initialize(scope_name) @scope_name = scope_name end |
Instance Method Details
#apply(query, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/filterameter/filters/conditional_scope_filter.rb', line 15 def apply(query, value) return query unless ActiveModel::Type::Boolean.new.cast(value) query.public_send(@scope_name) end |