Class: ActiveRecord::Refined::AST::Match

Inherits:
Predicate show all
Defined in:
lib/active_record/refined/ast.rb

Overview

Regular expression match: REGEXP on MySQL, ~ on PostgreSQL. SQLite has no regexp operator built in, so Arel raises NotImplementedError there.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(operand, pattern, negated: false) ⇒ Match

Returns a new instance of Match.



2339
2340
2341
2342
2343
# File 'lib/active_record/refined/ast.rb', line 2339

def initialize(operand, pattern, negated: false)
  @operand = operand
  @pattern = pattern.is_a?(Regexp) ? regexp_source(pattern) : pattern
  @negated = negated
end

Instance Attribute Details

#negatedObject (readonly)

Returns the value of attribute negated.



2337
2338
2339
# File 'lib/active_record/refined/ast.rb', line 2337

def negated
  @negated
end

#operandObject (readonly)

Returns the value of attribute operand.



2337
2338
2339
# File 'lib/active_record/refined/ast.rb', line 2337

def operand
  @operand
end

#patternObject (readonly)

Returns the value of attribute pattern.



2337
2338
2339
# File 'lib/active_record/refined/ast.rb', line 2337

def pattern
  @pattern
end

Instance Method Details

#to_arel(table, model) ⇒ Object



2345
2346
2347
2348
2349
2350
2351
2352
# File 'lib/active_record/refined/ast.rb', line 2345

def to_arel(table, model)
  arel_operand = to_arel_operand(operand, table, model)
  if negated
    arel_operand.does_not_match_regexp(pattern)
  else
    arel_operand.matches_regexp(pattern)
  end
end