Class: Queryko::Filters::Search
- Defined in:
- lib/queryko/filters/search.rb
Instance Attribute Summary collapse
-
#cond ⇒ Object
readonly
Returns the value of attribute cond.
-
#token_format ⇒ Object
readonly
Returns the value of attribute token_format.
Attributes inherited from Base
#as, #column_name, #feature, #field, #query_object, #table_name
Instance Method Summary collapse
- #format_query_params(token) ⇒ Object
-
#initialize(options = {}, feature) ⇒ Search
constructor
A new instance of Search.
- #perform(collection, token, query_object = nil) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}, feature) ⇒ Search
Returns a new instance of Search.
5 6 7 8 9 |
# File 'lib/queryko/filters/search.rb', line 5 def initialize( = {}, feature) @cond = .fetch(:cond) { :like } @token_format = [:token_format] || '%token%' super(, feature) end |
Instance Attribute Details
#cond ⇒ Object (readonly)
Returns the value of attribute cond.
4 5 6 |
# File 'lib/queryko/filters/search.rb', line 4 def cond @cond end |
#token_format ⇒ Object (readonly)
Returns the value of attribute token_format.
4 5 6 |
# File 'lib/queryko/filters/search.rb', line 4 def token_format @token_format end |
Instance Method Details
#format_query_params(token) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
11 12 13 14 15 16 |
# 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 |