Class: Filterameter::Filters::ConditionalScopeFilter

Inherits:
Object
  • Object
show all
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

#errors

Instance Method Summary collapse

Methods included from Errors

#valid?

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