Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4632

Show
Ignore:
Timestamp:
07/31/06 03:43:03 (2 years ago)
Author:
bitsweat
Message:

r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
Attribute methods
r4877@ks: jeremy | 2006-07-30 20:23:53 -0700
Factor the attribute#{suffix} methods out of method_missing for easier extension.
r4878@ks: jeremy | 2006-07-30 20:42:23 -0700
More specific method naming, declare many attribute method suffixes, set up default suffixes at module include rather than lazily.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4626 r4632  
    11*SVN* 
     2 
     3* Factor the attribute#{suffix} methods out of method_missing for easier extension. [Jeremy Kemper] 
    24 
    35* Patch sql injection vulnerability when using integer or float columns. [Jamis Buck] 
  • trunk/activerecord/lib/active_record.rb

    r4462 r4632  
    5353require 'active_record/calculations' 
    5454require 'active_record/xml_serialization' 
     55require 'active_record/attribute_methods' 
    5556 
    5657ActiveRecord::Base.class_eval do 
     
    7071  include ActiveRecord::Calculations 
    7172  include ActiveRecord::XmlSerialization 
     73  include ActiveRecord::AttributeMethods 
    7274end 
    7375 
  • trunk/activerecord/lib/active_record/base.rb

    r4604 r4632  
    16721672      def respond_to?(method, include_priv = false) 
    16731673        if @attributes.nil? 
    1674           return super  
     1674          return super 
    16751675        elsif attr_name = self.class.column_methods_hash[method.to_sym] 
    16761676          return true if @attributes.include?(attr_name) || attr_name == self.class.primary_key 
     
    16781678        elsif @attributes.include?(method_name = method.to_s) 
    16791679          return true 
    1680         elsif md = /(=|\?|_before_type_cast)$/.match(method_name
     1680        elsif md = self.class.match_attribute_method?(method.to_s
    16811681          return true if @attributes.include?(md.pre_match) 
    16821682        end 
     
    17501750        end 
    17511751      end 
     1752 
    17521753 
    17531754      # Allows access to the object attributes, which are held in the @attributes hash, as were 
     
    17681769        elsif self.class.primary_key.to_s == method_name 
    17691770          id 
    1770         elsif md = /(=|_before_type_cast)$/.match(method_name) 
     1771        elsif md = self.class.match_attribute_method?(method_name) 
    17711772          attribute_name, method_type = md.pre_match, md.to_s 
    17721773          if @attributes.include?(attribute_name) 
    1773             case method_type 
    1774               when '=' 
    1775                 write_attribute(attribute_name, args.first) 
    1776               when '_before_type_cast' 
    1777                 read_attribute_before_type_cast(attribute_name) 
    1778             end 
     1774            __send__("attribute#{method_type}", attribute_name, *args, &block) 
    17791775          else 
    17801776            super