Skip to content
This repository
Browse code

add deprecation warning for Sinatra::Default

  • Loading branch information...
commit 9cf0c0d59417ed37c9bbc410236a50826fc1fe76 1 parent 7a74c72
Ryan Tomayko authored March 04, 2010
2  compat/compat_test.rb
@@ -7,6 +7,6 @@
7 7
   end
8 8
 
9 9
   specify "makes EventContext available" do
10  
-    assert_same Sinatra::Default, Sinatra::EventContext
  10
+    assert_same Sinatra::Application, Sinatra::EventContext
11 11
   end
12 12
 end
19  lib/sinatra/base.rb
@@ -1080,9 +1080,9 @@ class << self
1080 1080
     end
1081 1081
   end
1082 1082
 
1083  
-  # The top-level Application. All DSL methods executed on main are delegated
1084  
-  # to this class.
1085  
-  class Application < Base
  1083
+  # Deprecated as base class for non-top-level apps. Subclass
  1084
+  # Sinatra::Base instead and set options as needed.
  1085
+  class Default < Base
1086 1086
     set :raise_errors, Proc.new { test? }
1087 1087
     set :show_exceptions, Proc.new { development? }
1088 1088
     set :dump_errors, true
@@ -1097,9 +1097,20 @@ def self.register(*extensions, &block) #:nodoc:
1097 1097
       Delegator.delegate(*added_methods)
1098 1098
       super(*extensions, &block)
1099 1099
     end
  1100
+
  1101
+    def self.inherited(subclass)
  1102
+      if subclass.to_s != 'Sinatra::Application'
  1103
+        sinatra_warn 'Sinatra::Default is deprecated;' +
  1104
+          ' subclass Sinatra::Base instead'
  1105
+      end
  1106
+      super
  1107
+    end
1100 1108
   end
1101 1109
 
1102  
-  Default = Application
  1110
+  # The top-level Application. All DSL methods executed on main are delegated
  1111
+  # to this class.
  1112
+  class Application < Default
  1113
+  end
1103 1114
 
1104 1115
   # Sinatra delegation mixin. Mixing this module into an object causes all
1105 1116
   # methods to be delegated to the Sinatra::Application class. Used primarily
6  lib/sinatra/compat.rb
@@ -48,9 +48,9 @@ module Compat #:nodoc:
48 48
   # Make Sinatra::EventContext an alias for Sinatra::Default to unbreak plugins.
49 49
   def self.const_missing(const_name) #:nodoc:
50 50
     if const_name == :EventContext
51  
-      const_set :EventContext, Sinatra::Default
52  
-      sinatra_warn 'Sinatra::EventContext is deprecated; use Sinatra::Default instead.'
53  
-      Sinatra::Default
  51
+      const_set :EventContext, Sinatra::Application
  52
+      sinatra_warn 'Sinatra::EventContext is deprecated; use Sinatra::Application instead.'
  53
+      Sinatra::Application
54 54
     else
55 55
       super
56 56
     end

0 notes on commit 9cf0c0d

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