Skip to content
This repository
Browse code

Make RAILS_* give deprecation warning just once

  • Loading branch information...
commit 25b6b95459ae71218754e8469f77f86b676bf215 1 parent 06860dc
Pratik authored February 04, 2010

Showing 1 changed file with 21 additions and 6 deletions. Show diff stats Hide diff stats

  1. 27  railties/lib/rails/deprecation.rb
27  railties/lib/rails/deprecation.rb
@@ -2,6 +2,9 @@
2 2
 require "active_support/deprecation"
3 3
 
4 4
 RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
  5
+  cattr_accessor :warned
  6
+  self.warned = false
  7
+
5 8
   def target
6 9
     Rails.root
7 10
   end
@@ -11,12 +14,17 @@ def replace(*args)
11 14
   end
12 15
 
13 16
   def warn(callstack, called, args)
14  
-    msg = "RAILS_ROOT is deprecated! Use Rails.root instead"
15  
-    ActiveSupport::Deprecation.warn(msg, callstack)
  17
+    unless warned
  18
+      ActiveSupport::Deprecation.warn("RAILS_ROOT is deprecated! Use Rails.root instead", callstack)
  19
+      self.warned = true
  20
+    end
16 21
   end
17 22
 end).new
18 23
 
19 24
 RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
  25
+  cattr_accessor :warned
  26
+  self.warned = false
  27
+
20 28
   def target
21 29
     Rails.env
22 30
   end
@@ -26,12 +34,17 @@ def replace(*args)
26 34
   end
27 35
 
28 36
   def warn(callstack, called, args)
29  
-    msg = "RAILS_ENV is deprecated! Use Rails.env instead"
30  
-    ActiveSupport::Deprecation.warn(msg, callstack)
  37
+    unless warned
  38
+      ActiveSupport::Deprecation.warn("RAILS_ENV is deprecated! Use Rails.env instead", callstack)
  39
+      self.warned = true
  40
+    end
31 41
   end
32 42
 end).new
33 43
 
34 44
 RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
  45
+  cattr_accessor :warned
  46
+  self.warned = false
  47
+
35 48
   def target
36 49
     Rails.logger
37 50
   end
@@ -41,7 +54,9 @@ def replace(*args)
41 54
   end
42 55
 
43 56
   def warn(callstack, called, args)
44  
-    msg = "RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead"
45  
-    ActiveSupport::Deprecation.warn(msg, callstack)
  57
+    unless warned
  58
+      ActiveSupport::Deprecation.warn("RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead", callstack)
  59
+      self.warned = true
  60
+    end
46 61
   end
47 62
 end).new

0 notes on commit 25b6b95

Please sign in to comment.
Something went wrong with that request. Please try again.