class Queryko::Filters::Search

Attributes

cond[R]
token_format[R]

Public Class Methods

new(options = {}, feature) click to toggle source
Calls superclass method Queryko::Filters::Base::new
# File lib/queryko/filters/search.rb, line 5
def initialize(options = {}, feature)
  @cond = options.fetch(:cond) { :like }
  @token_format = options[:token_format] || '%token%'
  super(options, feature)
end

Public Instance Methods

format_query_params(token) click to toggle source
# File lib/queryko/filters/search.rb, line 18
def format_query_params(token)
  case cond.to_sym
  when :like
    ['LIKE', token_format.gsub('token', token)]
  when :eq
    ['=', token]
  when :neq
    ['IS NOT', token]
  end
end
perform(collection, token, query_object = nil) click to toggle source
# File lib/queryko/filters/search.rb, line 11
def perform(collection, token, query_object = nil)
  query_cond, query_token = format_query_params(token)
  table_property = "#{table_name}.#{column_name}"

  collection.where("#{table_property} #{query_cond} ?", query_token)
end