diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-20 11:35:16 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-10-20 11:35:16 -0700 |
commit | 4ed156336faaa378e0329f4e96c3f4c30ddaee09 (patch) | |
tree | aa33ec39f3ee65559553279421c8df8515c3ea99 /activerecord/lib/active_record | |
parent | c869ce02265299994df4c2333228d1be7538a665 (diff) | |
download | rails-4ed156336faaa378e0329f4e96c3f4c30ddaee09.tar.gz rails-4ed156336faaa378e0329f4e96c3f4c30ddaee09.tar.bz2 rails-4ed156336faaa378e0329f4e96c3f4c30ddaee09.zip |
Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."
This reverts commit 83846838252397b3781eed165ca301e05db39293.
Diffstat (limited to 'activerecord/lib/active_record')
13 files changed, 51 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index b4d227eeee..59f209cec8 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/deprecation' module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :partial_writes, instance_accessor: false self.partial_writes = true end diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 1b1e732eb1..46fd6ebfb3 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -1,5 +1,5 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :attribute_types_cached_by_default, instance_accessor: false end diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index 95bbf68433..f36a5806a9 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -1,6 +1,6 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :time_zone_aware_attributes, instance_accessor: false self.time_zone_aware_attributes = false diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 258c222f7b..a4705b24ca 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -323,6 +323,6 @@ module ActiveRecord #:nodoc: class Base include ActiveRecord::Model end - - ActiveSupport.run_load_hooks(:active_record, Base) end + +ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Model::DeprecationProxy.new) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index f1e65f538b..f97c363871 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/object/duplicable' require 'thread' module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do ## # :singleton-method: # diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb index 72e09945b5..9e0390bed1 100644 --- a/activerecord/lib/active_record/explain.rb +++ b/activerecord/lib/active_record/explain.rb @@ -1,7 +1,7 @@ require 'active_support/lazy_load_hooks' module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :auto_explain_threshold_in_seconds, instance_accessor: false end diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 68e5b1dafa..35273b0d81 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -1,6 +1,6 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do # Determine whether to store the full constant name including namespace when using STI mattr_accessor :store_full_sti_class, instance_accessor: false self.store_full_sti_class = true diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 81195cb355..e96ed00f9c 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -1,5 +1,5 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :lock_optimistically, instance_accessor: false self.lock_optimistically = true end diff --git a/activerecord/lib/active_record/model.rb b/activerecord/lib/active_record/model.rb index 5fcb0359c5..f059840f4d 100644 --- a/activerecord/lib/active_record/model.rb +++ b/activerecord/lib/active_record/model.rb @@ -115,21 +115,52 @@ module ActiveRecord 'type' end end + + class DeprecationProxy < BasicObject #:nodoc: + def initialize(model = Model, base = Base) + @model = model + @base = base + end + + def method_missing(name, *args, &block) + if @model.respond_to?(name, true) + @model.send(name, *args, &block) + else + ::ActiveSupport::Deprecation.warn( + "The object passed to the active_record load hook was previously ActiveRecord::Base " \ + "(a Class). Now it is ActiveRecord::Model (a Module). You have called `#{name}' which " \ + "is only defined on ActiveRecord::Base. Please change your code so that it works with " \ + "a module rather than a class. (Model is included in Base, so anything added to Model " \ + "will be available on Base as well.)" + ) + @base.send(name, *args, &block) + end + end + + alias send method_missing + + def extend(*mods) + ::ActiveSupport::Deprecation.warn( + "The object passed to the active_record load hook was previously ActiveRecord::Base " \ + "(a Class). Now it is ActiveRecord::Model (a Module). You have called `extend' which " \ + "would add singleton methods to Model. This is presumably not what you want, since the " \ + "methods would not be inherited down to Base. Rather than using extend, please use " \ + "ActiveSupport::Concern + include, which will ensure that your class methods are " \ + "inherited." + ) + @base.extend(*mods) + end + end end - # This hook is where config accessors on Model should be defined. + # This hook is where config accessors on Model get defined. # # We don't want to just open the Model module and add stuff to it in other files, because # that would cause Model to load, which causes all sorts of loading order issues. # # We need this hook rather than just using the :active_record one, because users of the # :active_record hook may need to use config options. - # - # Users who wish to include a module in Model that they want to also - # get inherited by Base should do so using this load hook. After Base - # has included Model, any modules subsequently included in Model won't - # be inherited by Base. - ActiveSupport.run_load_hooks(:active_record_model, Model) + ActiveSupport.run_load_hooks(:active_record_config, Model) # Load Base at this point, because the active_record load hook is run in that file. Base diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 93bd21d7e9..99de16cd33 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -1,6 +1,6 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :primary_key_prefix_type, instance_accessor: false mattr_accessor :table_name_prefix, instance_accessor: false diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 4d1ff98eb3..2e7fb3bbb3 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/hash/indifferent_access' module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :nested_attributes_options, instance_accessor: false self.nested_attributes_options = {} end diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 6bdf0db95a..e8dd312a47 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -1,5 +1,5 @@ module ActiveRecord #:nodoc: - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :include_root_in_json, instance_accessor: false self.include_root_in_json = true end diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 9fb5be7861..ec4588f601 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -1,6 +1,6 @@ module ActiveRecord - ActiveSupport.on_load(:active_record_model) do + ActiveSupport.on_load(:active_record_config) do mattr_accessor :record_timestamps, instance_accessor: false self.record_timestamps = true end |