class Filterameter::Filters::MatchesFilter

Matches Filter

Class MatchesFilter uses arel's `matches` to generate a LIKE query.

Public Class Methods

new(attribute_name, options) click to toggle source
# File lib/filterameter/filters/matches_filter.rb, line 9
def initialize(attribute_name, options)
  @attribute_name = attribute_name
  @prefix = options.match_anywhere? ? '%' : nil
  @suffix = options.match_anywhere? || options.match_from_start? ? '%' : nil
  @case_sensitive = options.case_sensitive?
end

Public Instance Methods

apply(query, value) click to toggle source
# File lib/filterameter/filters/matches_filter.rb, line 16
def apply(query, value)
  arel = query.arel_table[@attribute_name].matches("#{@prefix}#{value}#{@suffix}", false, @case_sensitive)
  query.where(arel)
end