Class: Wallaby::ActiveRecord::ModelServiceProvider::Querier::Escaper
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelServiceProvider::Querier::Escaper
- Includes:
- ActiveRecord::Sanitization
- Defined in:
- lib/adapters/wallaby/active_record/model_service_provider/querier/escaper.rb
Overview
Build up query using the results
Constant Summary collapse
- LIKE_SIGN =
:nodoc:
/[%_]/.freeze
- PCT =
:nodoc:
'%'
Class Method Summary collapse
-
.execute(keyword) ⇒ String
Escaped string for LIKE query.
Class Method Details
.execute(keyword) ⇒ String
Returns escaped string for LIKE query.
22 23 24 25 26 27 28 29 30 31 32 |
# 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 |