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

Methods

Constants

SUFFIX_MAP = { 'eq'=>'=', 'lt'=>'<', 'lte'=>'<=', 'gt'=>'>', 'gte'=>'>=', 'ne'=>'!=', 'not'=>'!=' }

Public Class methods

[Source]

     # File lib/ar-extensions/extensions.rb, line 454
454:     def self.process( key, val, caller )
455:       return unless val.is_a?( Time )
456:       process_without_suffix( key, val, caller ) || process_with_suffix( key, val, caller )
457:     end

[Source]

     # File lib/ar-extensions/extensions.rb, line 470
470:     def self.process_with_suffix( key, val, caller )
471:       SUFFIX_MAP.each_pair do |k,v|
472:         match_data = key.to_s.match( /(.+)_#{k}$/ )
473:         if match_data
474:           fieldname = match_data.captures[0]
475:           return nil unless caller.columns_hash.has_key?( fieldname )
476:           str = "#{caller.table_name}.#{caller.connection.quote_column_name( fieldname )} " +
477:             "#{v} #{caller.connection.quote( val.to_s(:db), caller.columns_hash[ fieldname ] )} "
478:           return Result.new( str, nil )
479:         end
480:       end
481:       nil
482:     end

[Source]

     # File lib/ar-extensions/extensions.rb, line 459
459:     def self.process_without_suffix( key, val, caller )
460:       return nil unless caller.columns_hash.has_key?( key )
461:       if val.nil?
462:         str = "#{caller.table_name}.#{caller.connection.quote_column_name( key )} IS NULL"
463:       else
464:         str = "#{caller.table_name}.#{caller.connection.quote_column_name( key )}=" +
465:           "#{caller.connection.quote( val.to_s(:db), caller.columns_hash[ key ] )} "
466:       end
467:       Result.new( str, nil )
468:     end

[Validate]