From 0b7067d8497c4d832b32233888ce973ab4357e5d Mon Sep 17 00:00:00 2001 From: Nikita Afanasenko Date: Mon, 29 Oct 2012 19:22:59 +0400 Subject: Provide a call stack for deprecation warnings where needed. It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly. --- activerecord/lib/active_record/associations/association.rb | 2 +- activerecord/lib/active_record/attribute_methods/serialization.rb | 3 ++- .../lib/active_record/connection_adapters/abstract_adapter.rb | 7 ++++--- activerecord/lib/active_record/connection_adapters/column.rb | 5 +++-- .../connection_adapters/postgresql/database_statements.rb | 7 +++---- activerecord/lib/active_record/migration.rb | 5 ++--- activerecord/lib/active_record/readonly_attributes.rb | 3 ++- activerecord/lib/active_record/scoping/default.rb | 3 ++- activerecord/lib/active_record/scoping/named.rb | 3 ++- 9 files changed, 21 insertions(+), 17 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index ba75c8be41..7c09e23f27 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -85,7 +85,7 @@ module ActiveRecord end def scoped - ActiveSupport::Deprecation.warn("#scoped is deprecated. use #scope instead.") + ActiveSupport::Deprecation.warn("#scoped is deprecated. use #scope instead.", caller) scope end diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 9994a81ede..d8fe4afd54 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -45,7 +45,8 @@ module ActiveRecord end def serialized_attributes - ActiveSupport::Deprecation.warn("Instance level serialized_attributes method is deprecated, please use class level method.") + message = "Instance level serialized_attributes method is deprecated, please use class level method." + ActiveSupport::Deprecation.warn(message, caller) defined?(@serialized_attributes) ? @serialized_attributes : self.class.serialized_attributes end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 0cb219767b..0b03d413dc 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -255,15 +255,16 @@ module ActiveRecord end def increment_open_transactions - ActiveSupport::Deprecation.warn "#increment_open_transactions is deprecated and has no effect" + ActiveSupport::Deprecation.warn("#increment_open_transactions is deprecated and has no effect", caller) end def decrement_open_transactions - ActiveSupport::Deprecation.warn "#decrement_open_transactions is deprecated and has no effect" + ActiveSupport::Deprecation.warn("#decrement_open_transactions is deprecated and has no effect", caller) end def transaction_joinable=(joinable) - ActiveSupport::Deprecation.warn "#transaction_joinable= is deprecated. Please pass the :joinable option to #begin_transaction instead." + message = "#transaction_joinable= is deprecated. Please pass the :joinable option to #begin_transaction instead." + ActiveSupport::Deprecation.warn(message, caller) @transaction.joinable = joinable end diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 816b5e17c1..6dcab2e0bd 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -107,8 +107,9 @@ module ActiveRecord end def type_cast_code(var_name) - ActiveSupport::Deprecation.warn("Column#type_cast_code is deprecated in favor of" \ - "using Column#type_cast only, and it is going to be removed in future Rails versions.") + message = "Column#type_cast_code is deprecated in favor of using Column#type_cast only, " \ + "and it is going to be removed in future Rails versions." + ActiveSupport::Deprecation.warn(message, caller) klass = self.class.name diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 553985bd1e..e82e809414 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -221,10 +221,9 @@ module ActiveRecord end def outside_transaction? - ActiveSupport::Deprecation.warn( - "#outside_transaction? is deprecated. This method was only really used " \ - "internally, but you can use #transaction_open? instead." - ) + message = "#outside_transaction? is deprecated. This method was only really used " \ + "internally, but you can use #transaction_open? instead." + ActiveSupport::Deprecation.warn(message, caller) @connection.transaction_status == PGconn::PQTRANS_IDLE end diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 5c5417a0e1..fcadd4767d 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -732,9 +732,8 @@ module ActiveRecord running = runnable if block_given? - ActiveSupport::Deprecation.warn(<<-eomsg) -block argument to migrate is deprecated, please filter migrations before constructing the migrator - eomsg + message = "block argument to migrate is deprecated, please filter migrations before constructing the migrator" + ActiveSupport::Deprecation.warn(message, caller) running.select! { |m| yield m } end diff --git a/activerecord/lib/active_record/readonly_attributes.rb b/activerecord/lib/active_record/readonly_attributes.rb index b3c20c4aff..71921c79b0 100644 --- a/activerecord/lib/active_record/readonly_attributes.rb +++ b/activerecord/lib/active_record/readonly_attributes.rb @@ -22,7 +22,8 @@ module ActiveRecord end def _attr_readonly - ActiveSupport::Deprecation.warn("Instance level _attr_readonly method is deprecated, please use class level method.") + message = "Instance level _attr_readonly method is deprecated, please use class level method." + ActiveSupport::Deprecation.warn(message, caller) defined?(@_attr_readonly) ? @_attr_readonly : self.class._attr_readonly end end diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index 6835d0e01b..705b719a3a 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -95,7 +95,8 @@ module ActiveRecord "Calling #default_scope without a block is deprecated. For example instead " \ "of `default_scope where(color: 'red')`, please use " \ "`default_scope { where(color: 'red') }`. (Alternatively you can just redefine " \ - "self.default_scope.)" + "self.default_scope.)", + caller ) end diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index fb5f5b5be0..a91ac302cb 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -156,7 +156,8 @@ module ActiveRecord "`scope :red, -> { where(color: 'red') }`. There are numerous gotchas " \ "in the former usage and it makes the implementation more complicated " \ "and buggy. (If you prefer, you can just define a class method named " \ - "`self.red`.)" + "`self.red`.)", + caller ) end -- cgit v1.2.3