Class: ActiveRecord::Extensions::SqliteRegexp
- Inherits:
-
RegexpBase
- Object
- RegexpBase
- ActiveRecord::Extensions::SqliteRegexp
- Defined in:
- lib/ar-extensions/extensions.rb
Overview
ActiveRecord::Extension for implementing Regexp implementation for MySQL. See documention for RegexpBase.
Constant Summary
Constants inherited from RegexpBase
RegexpBase::EQUAL_RGX, RegexpBase::NOT_EQUAL_RGX
Class Method Summary collapse
Methods inherited from RegexpBase
Class Method Details
.add_rlike_function(connection) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/ar-extensions/extensions.rb', line 437 def self.add_rlike_function( connection ) self.connections << connection unless connection.respond_to?( 'sqlite_regexp_support?' ) class << connection def sqlite_regexp_support? ; true ; end end connection.instance_eval( '@connection' ).create_function( 'rlike', 3 ) do |func, a, b, negate| func.set_result 1 if negate.to_s == 'true' ? a.to_s !~ /#{b}/ : a.to_s =~ /#{b}/ end end end |
.process(key, val, caller) ⇒ Object
449 450 451 452 453 454 455 456 |
# File 'lib/ar-extensions/extensions.rb', line 449 def self.process( key, val, caller ) return nil unless val.is_a?( Regexp ) r = field_result( key, caller ) unless self.connections.include?( caller.connection ) add_rlike_function( caller.connection ) end Result.new( "rlike( #{r.fieldname}, ?, '#{r.negate?}' )", val ) end |