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.
1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/active_record/refined/ast.rb', line 1432 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.
1430 1431 1432 |
# File 'lib/active_record/refined/ast.rb', line 1430 def case_sensitive @case_sensitive end |
#escape ⇒ Object (readonly)
Returns the value of attribute escape.
1430 1431 1432 |
# File 'lib/active_record/refined/ast.rb', line 1430 def escape @escape end |
#negated ⇒ Object (readonly)
Returns the value of attribute negated.
1430 1431 1432 |
# File 'lib/active_record/refined/ast.rb', line 1430 def negated @negated end |
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
1430 1431 1432 |
# File 'lib/active_record/refined/ast.rb', line 1430 def operand @operand end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
1430 1431 1432 |
# File 'lib/active_record/refined/ast.rb', line 1430 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.
1425 1426 1427 1428 |
# File 'lib/active_record/refined/ast.rb', line 1425 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.
1419 1420 1421 |
# File 'lib/active_record/refined/ast.rb', line 1419 def self.escape(string) ActiveRecord::Base.sanitize_sql_like(string, ESCAPE) end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1441 1442 1443 1444 1445 1446 1447 |
# File 'lib/active_record/refined/ast.rb', line 1441 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 |