Class: Filterameter::Filters::MatchesFilter
- Inherits:
-
Object
- Object
- Filterameter::Filters::MatchesFilter
- Includes:
- Errors, AttributeValidator
- Defined in:
- lib/filterameter/filters/matches_filter.rb
Overview
# Matches Filter
Class MatchesFilter uses arel’s ‘matches` to generate a LIKE query.
Instance Attribute Summary
Attributes included from Errors
Instance Method Summary collapse
- #apply(query, value) ⇒ Object
-
#initialize(attribute_name, options) ⇒ MatchesFilter
constructor
A new instance of MatchesFilter.
Methods included from Errors
Constructor Details
#initialize(attribute_name, options) ⇒ MatchesFilter
Returns a new instance of MatchesFilter.
12 13 14 15 16 17 |
# File 'lib/filterameter/filters/matches_filter.rb', line 12 def initialize(attribute_name, ) @attribute_name = attribute_name @prefix = .match_anywhere? ? '%' : nil @suffix = .match_anywhere? || .match_from_start? ? '%' : nil @case_sensitive = .case_sensitive? end |
Instance Method Details
#apply(query, value) ⇒ Object
19 20 21 22 |
# File 'lib/filterameter/filters/matches_filter.rb', line 19 def apply(query, value) arel = query.arel_table[@attribute_name].matches("#{@prefix}#{value}#{@suffix}", false, @case_sensitive) query.where(arel) end |