Class: ActiveRecord::Refined::AST::Like
- Defined in:
- lib/active_record/refined/ast.rb
Constant Summary collapse
- ESCAPE =
"\\".freeze
Instance Attribute Summary collapse
-
#escape ⇒ Object
readonly
Returns the value of attribute escape.
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
-
.escape(string) ⇒ Object
Escapes % and _ so that they match literally.
Instance Method Summary collapse
-
#initialize(operand, pattern, escape = nil) ⇒ Like
constructor
A new instance of Like.
- #to_arel(table) ⇒ Object
Methods inherited from Predicate
Methods inherited from Node
Constructor Details
#initialize(operand, pattern, escape = nil) ⇒ Like
Returns a new instance of Like.
248 249 250 251 252 |
# File 'lib/active_record/refined/ast.rb', line 248 def initialize(operand, pattern, escape = nil) @operand = operand @pattern = pattern @escape = escape end |
Instance Attribute Details
#escape ⇒ Object (readonly)
Returns the value of attribute escape.
246 247 248 |
# File 'lib/active_record/refined/ast.rb', line 246 def escape @escape end |
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
246 247 248 |
# File 'lib/active_record/refined/ast.rb', line 246 def operand @operand end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
246 247 248 |
# File 'lib/active_record/refined/ast.rb', line 246 def pattern @pattern end |
Class Method Details
.escape(string) ⇒ Object
Escapes % and _ so that they match literally. The pattern built from the result must be used with ESCAPE, since SQLite has no default escape character.
242 243 244 |
# File 'lib/active_record/refined/ast.rb', line 242 def self.escape(string) ActiveRecord::Base.sanitize_sql_like(string, ESCAPE) end |
Instance Method Details
#to_arel(table) ⇒ Object
254 255 256 257 258 |
# File 'lib/active_record/refined/ast.rb', line 254 def to_arel(table) # Arel matches case-insensitively unless told otherwise, which turns # into ILIKE on PostgreSQL. like? means SQL LIKE on every adapter. to_arel_operand(operand, table).matches(pattern, escape, true) end |