Skip to content
This repository
Newer
Older
100644 51 lines (44 sloc) 2.083 kb
e8550ee0 »
2009-05-13 Cherry-pick core extensions
1 require 'active_support/core_ext/enumerable'
2
2b3cc247 »
2006-07-31 r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
3 module ActiveRecord
4 module AttributeMethods #:nodoc:
4e50a35f »
2009-05-28 Break up DependencyModule's dual function of providing a "depend_on" …
5 extend ActiveSupport::Concern
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
6 include ActiveModel::AttributeMethods
a2875bec »
2009-05-11 Use DependencyModule for included hooks in ActiveRecord
7
2b3cc247 »
2006-07-31 r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
8 module ClassMethods
46f30f90 »
2008-05-16 Merge documentation changes from docrails.
9 # Generates all the attribute related methods for columns in the database
10 # accessors, mutators and query methods.
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
11 def define_attribute_methods
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
12 super(columns_hash.keys)
e129c567 »
2009-07-29 Wrap up attribute method reset concerns in 'undefine_attribute_methods'
13 end
14
46f30f90 »
2008-05-16 Merge documentation changes from docrails.
15 # Checks whether the method is defined in the model or any of its subclasses
3e58f8e1 »
2009-07-30 Restore DangerousAttributeError
16 # that also derive from Active Record. Raises DangerousAttributeError if the
17 # method is defined by Active Record though.
b31aa639 »
2007-10-03 Allow column accessors to be created even if Kernel. or Object# metho…
18 def instance_method_already_implemented?(method_name)
240b4c52 »
2007-12-27 Ruby 1.9 compat: attribute methods
19 method_name = method_name.to_s
3e58f8e1 »
2009-07-30 Restore DangerousAttributeError
20 @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map {|m| m.to_s }.to_set
21 @@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map{|m| m.to_s }.to_set
22 raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord" if @@_defined_activerecord_methods.include?(method_name)
5b2e8b1e »
2007-10-06 Fix that ActiveRecord would create attribute methods and override cus…
23 @_defined_class_methods.include?(method_name)
b31aa639 »
2007-10-03 Allow column accessors to be created even if Kernel. or Object# metho…
24 end
c30a0ce3 »
2009-08-04 Modified ActiveRecord::AttributeMethods to allow classes to specify a…
25 end
64eecdd1 »
2009-08-04 whitespace
26
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
27 def method_missing(method_id, *args, &block)
28 # If we haven't generated any methods yet, generate them, then
29 # see if we've created the method we're looking for.
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
30 if !self.class.attribute_methods_generated?
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
31 self.class.define_attribute_methods
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
32 method_name = method_id.to_s
d60d7edc »
2009-07-08 Make it so AR attributes which conflict with object-private methods (…
33 guard_private_attribute_method!(method_name, args)
364a8f39 »
2009-11-14 No need to check for generated method, just redispatch
34 send(method_id, *args, &block)
35 else
36 super
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
37 end
38 end
39
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
40 def respond_to?(*args)
41 self.class.define_attribute_methods
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
42 super
43 end
2b3cc247 »
2006-07-31 r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
44
f8d3c72c »
2009-08-04 Extract generic attribute method generation to AMo
45 protected
46 def attribute_method?(attr_name)
47 attr_name == 'id' || attributes.include?(attr_name)
5b801b59 »
2007-08-14 Change the implementation of ActiveRecord's attribute reader and writ…
48 end
2b3cc247 »
2006-07-31 r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
49 end
50 end
Something went wrong with that request. Please try again.