Class: Babik::Selection::Operation::IRegex

Inherits:
Regex
  • Object
show all
Defined in:
lib/babik/queryset/lib/selection/operation/regex.rb

Overview

Match by case insensitive regex

Instance Attribute Summary

Attributes inherited from Base

#field, #sql_operation, #sql_operation_template, #value

Instance Method Summary collapse

Methods inherited from Regex

#_mysql2_convert_regex

Methods inherited from Base

#_init_sql_operation, date_special_cases, #db_engine, escape, factory, initialize_operation, initialize_operators, operator?, special_cases, #to_s

Constructor Details

#initialize(field, value) ⇒ IRegex

Returns a new instance of IRegex.



39
40
41
42
43
44
45
# File 'lib/babik/queryset/lib/selection/operation/regex.rb', line 39

def initialize(field, value)
  value = value.inspect[1..-2] if value.class == Regexp
  value = value[1..-2] if value.class == String && value[0] == '/' && value[-1] == '/'
  value = "(?i)#{value}" if db_engine == 'sqlite3'
  field = "LOWER(#{field})" if db_engine == 'mysql2'
  super(field, value)
end

Instance Method Details

#operatorObject

Raises:

  • (NotImplementedError)


47
48
49
50
51
52
53
# File 'lib/babik/queryset/lib/selection/operation/regex.rb', line 47

def operator
  dbms_adapter = db_engine
  return 'REGEXP' if dbms_adapter == 'mysql2'
  return '~*' if dbms_adapter == 'postgresql'
  return 'REGEXP' if dbms_adapter == 'sqlite3'
  raise NotImplementedError, "Invalid dbms #{dbms_adapter}. Only mysql, postgresql, and sqlite3 are accepted"
end