Class ActiveRecord::Extensions::RegexpBase
In: lib/ar-extensions/extensions.rb
Parent: Object

A base class for database vendor specific Regexp implementations. This is meant to be subclassed only because of the helper method(s) it provides.

Methods

Classes and Modules

Class ActiveRecord::Extensions::RegexpBase::RegexpResult

Constants

NOT_EQUAL_RGX = /^(.+)_(ne|not|does_not_match)$/

Public Class methods

Given the passed in str and caller this will return a RegexpResult object which gives the database quoted fieldname/column and can tell you whether or not the original str is indicating a negated regular expression.

Examples

 r = RegexpBase.field_result( 'id' )
 r.fieldname => # 'id'
 r.negate?   => # false

 r = RegexpBase.field_result( 'id_ne' )
 r.fieldname => # 'id'
 r.negate?   => # true

 r = RegexpBase.field_result( 'id_not' )
 r.fieldname => # 'id'
 r.negate?   => # true

 r = RegexpBase.field_result( 'id_does_not_match' )
 r.fieldname => # 'id'
 r.negate?   => # true

[Source]

     # File lib/ar-extensions/extensions.rb, line 364
364:     def self.field_result( str, caller )
365:       negate = false
366:       if match_data=str.to_s.match( NOT_EQUAL_RGX )
367:         negate = true
368:         str = match_data.captures[0]
369:       end      
370:       fieldname = caller.connection.quote_column_name( str )
371:       RegexpResult.new( fieldname, negate )
372:     end

[Validate]