Class: ActiveRecord::Refined::AST::Like
- Defined in:
- lib/active_record/refined/ast.rb
Constant Summary collapse
- ESCAPE =
"\\".freeze
Instance Attribute Summary collapse
-
#case_sensitive ⇒ Object
readonly
Returns the value of attribute case_sensitive.
-
#escape ⇒ Object
readonly
Returns the value of attribute escape.
-
#negated ⇒ Object
readonly
Returns the value of attribute negated.
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
-
.any(operand, patterns) ⇒ Object
ORs one LIKE per pattern, for the shortcuts that accept several literals the way String#start_with? does.
-
.escape(string) ⇒ Object
Escapes % and _ so that they match literally.
Instance Method Summary collapse
-
#initialize(operand, pattern, escape = nil, case_sensitive: true, negated: false) ⇒ Like
constructor
A new instance of Like.
- #to_arel(table, model) ⇒ Object
Methods inherited from Predicate
Methods inherited from Node
Constructor Details
#initialize(operand, pattern, escape = nil, case_sensitive: true, negated: false) ⇒ Like
Returns a new instance of Like.
1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'lib/active_record/refined/ast.rb', line 1297 def initialize(operand, pattern, escape = nil, case_sensitive: true, negated: false) @operand = operand @pattern = pattern @escape = escape @case_sensitive = case_sensitive @negated = negated end |
Instance Attribute Details
#case_sensitive ⇒ Object (readonly)
Returns the value of attribute case_sensitive.
1295 1296 1297 |
# File 'lib/active_record/refined/ast.rb', line 1295 def case_sensitive @case_sensitive end |
#escape ⇒ Object (readonly)
Returns the value of attribute escape.
1295 1296 1297 |
# File 'lib/active_record/refined/ast.rb', line 1295 def escape @escape end |
#negated ⇒ Object (readonly)
Returns the value of attribute negated.
1295 1296 1297 |
# File 'lib/active_record/refined/ast.rb', line 1295 def negated @negated end |
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
1295 1296 1297 |
# File 'lib/active_record/refined/ast.rb', line 1295 def operand @operand end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
1295 1296 1297 |
# File 'lib/active_record/refined/ast.rb', line 1295 def pattern @pattern end |
Class Method Details
.any(operand, patterns) ⇒ Object
ORs one LIKE per pattern, for the shortcuts that accept several literals the way String#start_with? does.
1290 1291 1292 1293 |
# File 'lib/active_record/refined/ast.rb', line 1290 def self.any(operand, patterns) patterns.map {|pattern| new(operand, pattern, ESCAPE) }. inject {|left, right| Or.new(left, right) } end |
.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.
1284 1285 1286 |
# File 'lib/active_record/refined/ast.rb', line 1284 def self.escape(string) ActiveRecord::Base.sanitize_sql_like(string, ESCAPE) end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1306 1307 1308 1309 1310 1311 1312 |
# File 'lib/active_record/refined/ast.rb', line 1306 def to_arel(table, model) # Arel matches case-insensitively unless told otherwise, which is # what picks ILIKE over LIKE on PostgreSQL. to_arel_operand(operand, table, model). public_send(negated ? :does_not_match : :matches, pattern, escape, case_sensitive) end |