class Wallaby::ActiveRecord::ModelServiceProvider::Querier::Escaper
Build up query using the results
Public Class Methods
execute(keyword)
click to toggle source
@example Return the escaped keyword if the first/last char of the keyword is `%`/`_`
Wallaby::ActiveRecord::ModelServiceProvider::Querier::Escaper.execute('%something_else%') # => '%something\_else%'
@example Return the escaped keyword wrapped with `%` if the first/last char of the keyword is NOT `%`/`_`
Wallaby::ActiveRecord::ModelServiceProvider::Querier::Escaper.execute('keyword') # => '%keyword%'
@param keyword [String] @return [String] escaped string for LIKE query
# File lib/adapters/wallaby/active_record/model_service_provider/querier/escaper.rb, line 22 def execute(keyword) first = keyword.first last = keyword.last start_with, start_index = LIKE_SIGN.match?(first) ? [true, 1] : [false, 0] end_with, end_index = LIKE_SIGN.match?(last) ? [true, -2] : [false, -1] escaped = sanitize_sql_like keyword[start_index..end_index] starting = sign(start_with, first, end_with) ending = sign(end_with, last, start_with) "#{starting}#{escaped}#{ending}" end
Protected Class Methods
sign( first_condition, first_char, second_condition, default_sign = PCT )
click to toggle source
@param first_condition [Boolean] first condition @param first_char [Boolean] first char @param second_condition [nil, String] second condition @param default_sign [String]
# File lib/adapters/wallaby/active_record/model_service_provider/querier/escaper.rb, line 40 def sign( first_condition, first_char, second_condition, default_sign = PCT ) return first_char if first_condition return if second_condition default_sign end