Skip to content
This repository
Browse code

deprecate Sinatra::Default

  • Loading branch information...
commit 7196fa83c52168106c10c8010236563622497af2 1 parent 2a8eb72
Ryan Tomayko authored March 04, 2010
5  CHANGES
@@ -11,6 +11,11 @@
11 11
  * New 'settings' method gives access to options in both class and request
12 12
    scopes. This replaces the 'options' method. (Chris Wanstrath)
13 13
 
  14
+ * `Sinatra::Default` is obsolete; use `Sinatra::Base` instead.
  15
+   `Sinatra::Base` acts more like `Sinatra::Default` in development mode.
  16
+   For example, static file serving and sexy development error pages are
  17
+   enabled by default.
  18
+
14 19
  * The `:methodoverride' option to enable/disable the POST _method hack is
15 20
    obsolete; use `:method_override` instead.
16 21
 
41  lib/sinatra/base.rb
@@ -1084,7 +1084,6 @@ class << self
1084 1084
   # Sinatra::Base instead and set options as needed.
1085 1085
   class Default < Base
1086 1086
     set :raise_errors, Proc.new { test? }
1087  
-    set :show_exceptions, Proc.new { development? }
1088 1087
     set :dump_errors, true
1089 1088
     set :sessions, false
1090 1089
     set :logging, Proc.new { ! test? }
@@ -1092,24 +1091,34 @@ class Default < Base
1092 1091
     set :run, Proc.new { ! test? }
1093 1092
     set :static, true
1094 1093
 
1095  
-    def self.register(*extensions, &block) #:nodoc:
1096  
-      added_methods = extensions.map {|m| m.public_instance_methods }.flatten
1097  
-      Delegator.delegate(*added_methods)
1098  
-      super(*extensions, &block)
1099  
-    end
1100  
-
1101 1094
     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
  1095
+      sinatra_warn 'Sinatra::Default is deprecated; ' \
  1096
+                   'subclass Sinatra::Base instead'
1106 1097
       super
1107 1098
     end
1108 1099
   end
1109 1100
 
1110  
-  # The top-level Application. All DSL methods executed on main are delegated
1111  
-  # to this class.
1112  
-  class Application < Default
  1101
+  # Execution context for classic style (top-level) applications. All
  1102
+  # DSL methods executed on main are delegated to this class.
  1103
+  #
  1104
+  # The Application class should not be subclassed, unless you want to
  1105
+  # inherit all settings, routes, handlers, and error pages from the
  1106
+  # top-level. Subclassing Sinatra::Base is heavily recommended for
  1107
+  # modular applications.
  1108
+  class Application < Base
  1109
+    set :raise_errors, Proc.new { test? }
  1110
+    set :dump_errors, true
  1111
+    set :sessions, false
  1112
+    set :logging, Proc.new { ! test? }
  1113
+    set :method_override, true
  1114
+    set :run, Proc.new { ! test? }
  1115
+    set :static, true
  1116
+
  1117
+    def self.register(*extensions, &block) #:nodoc:
  1118
+      added_methods = extensions.map {|m| m.public_instance_methods }.flatten
  1119
+      Delegator.delegate(*added_methods)
  1120
+      super(*extensions, &block)
  1121
+    end
1113 1122
   end
1114 1123
 
1115 1124
   # Sinatra delegation mixin. Mixing this module into an object causes all
@@ -1143,12 +1152,12 @@ def self.new(base=Base, options={}, &block)
1143 1152
 
1144 1153
   # Extend the top-level DSL with the modules provided.
1145 1154
   def self.register(*extensions, &block)
1146  
-    Default.register(*extensions, &block)
  1155
+    Application.register(*extensions, &block)
1147 1156
   end
1148 1157
 
1149 1158
   # Include the helper modules provided in Sinatra's request context.
1150 1159
   def self.helpers(*extensions, &block)
1151  
-    Default.helpers(*extensions, &block)
  1160
+    Application.helpers(*extensions, &block)
1152 1161
   end
1153 1162
 end
1154 1163
 
2  lib/sinatra/compat.rb
@@ -45,7 +45,7 @@ module Sinatra
45 45
   module Compat #:nodoc:
46 46
   end
47 47
 
48  
-  # Make Sinatra::EventContext an alias for Sinatra::Default to unbreak plugins.
  48
+  # Make Sinatra::EventContext an alias for Sinatra::Application to unbreak plugins.
49 49
   def self.const_missing(const_name) #:nodoc:
50 50
     if const_name == :EventContext
51 51
       const_set :EventContext, Sinatra::Application
2  lib/sinatra/main.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'sinatra/base'
2 2
 
3 3
 module Sinatra
4  
-  class Default < Base
  4
+  class Application < Base
5 5
 
6 6
     # we assume that the first file that requires 'sinatra' is the
7 7
     # app_file. all other path related options are calculated based
2  lib/sinatra/test.rb
@@ -7,7 +7,7 @@ module Test
7 7
     include Rack::Utils
8 8
 
9 9
     def self.included(base)
10  
-      Sinatra::Default.set(:environment, :test)
  10
+      Sinatra::Application.set(:environment, :test)
11 11
     end
12 12
 
13 13
     attr_reader :app, :request, :response
2  lib/sinatra/test/bacon.rb
@@ -3,7 +3,7 @@
3 3
 
4 4
 Sinatra::Test.deprecate('Bacon')
5 5
 
6  
-Sinatra::Default.set(
  6
+Sinatra::Application.set(
7 7
   :environment => :test,
8 8
   :run => false,
9 9
   :raise_errors => true,
2  lib/sinatra/test/rspec.rb
@@ -5,7 +5,7 @@
5 5
 
6 6
 Sinatra::Test.deprecate('RSpec')
7 7
 
8  
-Sinatra::Default.set(
  8
+Sinatra::Application.set(
9 9
   :environment => :test,
10 10
   :run => false,
11 11
   :raise_errors => true,
2  lib/sinatra/test/unit.rb
@@ -5,7 +5,7 @@
5 5
 
6 6
 Test::Unit::TestCase.send :include, Sinatra::Test
7 7
 
8  
-Sinatra::Default.set(
  8
+Sinatra::Application.set(
9 9
   :environment => :test,
10 10
   :run => false,
11 11
   :raise_errors => true,
16  test/extensions_test.rb
@@ -35,9 +35,9 @@ def fizz!(name); end
35 35
     Sinatra::Base.register FooExtensions
36 36
     assert Sinatra::Base.respond_to?(:foo)
37 37
 
38  
-    Sinatra::Default.register BarExtensions
39  
-    assert Sinatra::Default.respond_to?(:bar)
40  
-    assert Sinatra::Default.respond_to?(:foo)
  38
+    Sinatra::Application.register BarExtensions
  39
+    assert Sinatra::Application.respond_to?(:bar)
  40
+    assert Sinatra::Application.respond_to?(:foo)
41 41
     assert !Sinatra::Base.respond_to?(:bar)
42 42
   end
43 43
 
@@ -48,8 +48,8 @@ def im_in_ur_anonymous_module; end
48 48
     assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
49 49
   end
50 50
 
51  
-  it 'will make sure any public methods added via Default#register are delegated to Sinatra::Delegator' do
52  
-    Sinatra::Default.register FooExtensions
  51
+  it 'will make sure any public methods added via Application#register are delegated to Sinatra::Delegator' do
  52
+    Sinatra::Application.register FooExtensions
53 53
     assert Sinatra::Delegator.private_instance_methods.
54 54
       map { |m| m.to_sym }.include?(:foo)
55 55
     assert !Sinatra::Delegator.private_instance_methods.
@@ -57,7 +57,7 @@ def im_in_ur_anonymous_module; end
57 57
   end
58 58
 
59 59
   it 'will handle special method names' do
60  
-    Sinatra::Default.register PainExtensions
  60
+    Sinatra::Application.register PainExtensions
61 61
     assert Sinatra::Delegator.private_instance_methods.
62 62
       map { |m| m.to_sym }.include?(:foo=)
63 63
     assert Sinatra::Delegator.private_instance_methods.
@@ -71,10 +71,10 @@ def im_in_ur_anonymous_module; end
71 71
     assert !Sinatra::Delegator.private_instance_methods.include?("quux")
72 72
   end
73 73
 
74  
-  it 'will extend the Sinatra::Default application by default' do
  74
+  it 'will extend the Sinatra::Application by default' do
75 75
     Sinatra.register BazExtensions
76 76
     assert !Sinatra::Base.respond_to?(:baz)
77  
-    assert Sinatra::Default.respond_to?(:baz)
  77
+    assert Sinatra::Application.respond_to?(:baz)
78 78
   end
79 79
 
80 80
   module BizzleExtension
2  test/middleware_test.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 class MiddlewareTest < Test::Unit::TestCase
4 4
   setup do
5  
-    @app = mock_app(Sinatra::Default) {
  5
+    @app = mock_app(Sinatra::Base) {
6 6
       get '/*' do
7 7
         response.headers['X-Tests'] = env['test.ran'].
8 8
           map { |n| n.split('::').last }.
98  test/options_test.rb
@@ -3,9 +3,9 @@
3 3
 class OptionsTest < Test::Unit::TestCase
4 4
   setup do
5 5
     @base    = Sinatra.new(Sinatra::Base)
6  
-    @default = Sinatra.new(Sinatra::Default)
  6
+    @application = Sinatra.new(Sinatra::Application)
7 7
     @base.set    :environment, :development
8  
-    @default.set :environment, :development
  8
+    @application.set :environment, :development
9 9
   end
10 10
 
11 11
   it 'sets options to literal values' do
@@ -110,8 +110,8 @@ def clean_backtrace(trace)
110 110
       assert @base.clean_trace?
111 111
     end
112 112
 
113  
-    it 'is enabled on Default' do
114  
-      assert @default.clean_trace?
  113
+    it 'is enabled on Application' do
  114
+      assert @application.clean_trace?
115 115
     end
116 116
 
117 117
     it 'does nothing when disabled' do
@@ -152,13 +152,13 @@ def clean_backtrace(trace)
152 152
       assert ! @base.run?
153 153
     end
154 154
 
155  
-    it 'is enabled on Default when not in test environment' do
156  
-      @default.set :environment, :development
157  
-      assert @default.development?
158  
-      assert @default.run?
  155
+    it 'is enabled on Application when not in test environment' do
  156
+      @application.set :environment, :development
  157
+      assert @application.development?
  158
+      assert @application.run?
159 159
 
160  
-      @default.set :environment, :development
161  
-      assert @default.run?
  160
+      @application.set :environment, :development
  161
+      assert @application.run?
162 162
     end
163 163
 
164 164
     # TODO: it 'is enabled when $0 == app_file'
@@ -172,16 +172,16 @@ def clean_backtrace(trace)
172 172
       assert !@base.raise_errors?
173 173
     end
174 174
 
175  
-    it 'is enabled on Default only in test' do
176  
-      @default.set(:environment, :development)
177  
-      assert @default.development?
178  
-      assert ! @default.raise_errors?
  175
+    it 'is enabled on Application only in test' do
  176
+      @application.set(:environment, :development)
  177
+      assert @application.development?
  178
+      assert ! @application.raise_errors?
179 179
 
180  
-      @default.set(:environment, :production)
181  
-      assert ! @default.raise_errors?
  180
+      @application.set(:environment, :production)
  181
+      assert ! @application.raise_errors?
182 182
 
183  
-      @default.set(:environment, :test)
184  
-      assert @default.raise_errors?
  183
+      @application.set(:environment, :test)
  184
+      assert @application.raise_errors?
185 185
     end
186 186
   end
187 187
 
@@ -193,20 +193,20 @@ def clean_backtrace(trace)
193 193
       assert @base.show_exceptions?
194 194
     end
195 195
 
196  
-    it 'is enabled on Default only in development' do
  196
+    it 'is enabled on Application only in development' do
197 197
       @base.set(:environment, :development)
198  
-      assert @default.development?
199  
-      assert @default.show_exceptions?
  198
+      assert @application.development?
  199
+      assert @application.show_exceptions?
200 200
 
201  
-      @default.set(:environment, :test)
202  
-      assert ! @default.show_exceptions?
  201
+      @application.set(:environment, :test)
  202
+      assert ! @application.show_exceptions?
203 203
 
204 204
       @base.set(:environment, :production)
205 205
       assert ! @base.show_exceptions?
206 206
     end
207 207
 
208 208
     it 'returns a friendly 500' do
209  
-      klass = Sinatra.new(Sinatra::Default)
  209
+      klass = Sinatra.new(Sinatra::Application)
210 210
       mock_app(klass) {
211 211
         enable :show_exceptions
212 212
 
@@ -230,12 +230,12 @@ def clean_backtrace(trace)
230 230
       assert @base.dump_errors?
231 231
     end
232 232
 
233  
-    it 'is enabled on Default' do
234  
-      assert @default.dump_errors?
  233
+    it 'is enabled on Application' do
  234
+      assert @application.dump_errors?
235 235
     end
236 236
 
237 237
     it 'dumps exception with backtrace to rack.errors' do
238  
-      klass = Sinatra.new(Sinatra::Default)
  238
+      klass = Sinatra.new(Sinatra::Application)
239 239
 
240 240
       mock_app(klass) {
241 241
         disable :raise_errors
@@ -262,8 +262,8 @@ def clean_backtrace(trace)
262 262
       assert ! @base.sessions?
263 263
     end
264 264
 
265  
-    it 'is disabled on Default' do
266  
-      assert ! @default.sessions?
  265
+    it 'is disabled on Application' do
  266
+      assert ! @application.sessions?
267 267
     end
268 268
 
269 269
     # TODO: it 'uses Rack::Session::Cookie when enabled' do
@@ -274,18 +274,18 @@ def clean_backtrace(trace)
274 274
       assert ! @base.logging?
275 275
     end
276 276
 
277  
-    it 'is enabled on Default when not in test environment' do
278  
-      assert @default.logging?
  277
+    it 'is enabled on Application when not in test environment' do
  278
+      assert @application.logging?
279 279
 
280  
-      @default.set :environment, :test
281  
-      assert ! @default.logging
  280
+      @application.set :environment, :test
  281
+      assert ! @application.logging
282 282
     end
283 283
 
284 284
     # TODO: it 'uses Rack::CommonLogger when enabled' do
285 285
   end
286 286
 
287 287
   describe 'static' do
288  
-    it 'is disabled on Base by default' do
  288
+    it 'is disabled on Base by Application' do
289 289
       assert ! @base.static?
290 290
     end
291 291
 
@@ -301,81 +301,81 @@ def clean_backtrace(trace)
301 301
       assert @base.static?
302 302
     end
303 303
 
304  
-    it 'is enabled on Default' do
305  
-      assert @default.static?
  304
+    it 'is enabled on Application' do
  305
+      assert @application.static?
306 306
     end
307 307
   end
308 308
 
309 309
   describe 'host' do
310 310
     it 'defaults to 0.0.0.0' do
311 311
       assert_equal '0.0.0.0', @base.host
312  
-      assert_equal '0.0.0.0', @default.host
  312
+      assert_equal '0.0.0.0', @application.host
313 313
     end
314 314
   end
315 315
 
316 316
   describe 'port' do
317 317
     it 'defaults to 4567' do
318 318
       assert_equal 4567, @base.port
319  
-      assert_equal 4567, @default.port
  319
+      assert_equal 4567, @application.port
320 320
     end
321 321
   end
322 322
 
323 323
   describe 'server' do
324 324
     it 'is one of thin, mongrel, webrick' do
325 325
       assert_equal %w[thin mongrel webrick], @base.server
326  
-      assert_equal %w[thin mongrel webrick], @default.server
  326
+      assert_equal %w[thin mongrel webrick], @application.server
327 327
     end
328 328
   end
329 329
 
330 330
   describe 'app_file' do
331 331
     it 'is nil' do
332 332
       assert @base.app_file.nil?
333  
-      assert @default.app_file.nil?
  333
+      assert @application.app_file.nil?
334 334
     end
335 335
   end
336 336
 
337 337
   describe 'root' do
338 338
     it 'is nil if app_file is not set' do
339 339
       assert @base.root.nil?
340  
-      assert @default.root.nil?
  340
+      assert @application.root.nil?
341 341
     end
342 342
 
343 343
     it 'is equal to the expanded basename of app_file' do
344 344
       @base.app_file = __FILE__
345 345
       assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
346 346
 
347  
-      @default.app_file = __FILE__
348  
-      assert_equal File.expand_path(File.dirname(__FILE__)), @default.root
  347
+      @application.app_file = __FILE__
  348
+      assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
349 349
     end
350 350
   end
351 351
 
352 352
   describe 'views' do
353 353
     it 'is nil if root is not set' do
354 354
       assert @base.views.nil?
355  
-      assert @default.views.nil?
  355
+      assert @application.views.nil?
356 356
     end
357 357
 
358 358
     it 'is set to root joined with views/' do
359 359
       @base.root = File.dirname(__FILE__)
360 360
       assert_equal File.dirname(__FILE__) + "/views", @base.views
361 361
 
362  
-      @default.root = File.dirname(__FILE__)
363  
-      assert_equal File.dirname(__FILE__) + "/views", @default.views
  362
+      @application.root = File.dirname(__FILE__)
  363
+      assert_equal File.dirname(__FILE__) + "/views", @application.views
364 364
     end
365 365
   end
366 366
 
367 367
   describe 'public' do
368 368
     it 'is nil if root is not set' do
369 369
       assert @base.public.nil?
370  
-      assert @default.public.nil?
  370
+      assert @application.public.nil?
371 371
     end
372 372
 
373 373
     it 'is set to root joined with public/' do
374 374
       @base.root = File.dirname(__FILE__)
375 375
       assert_equal File.dirname(__FILE__) + "/public", @base.public
376 376
 
377  
-      @default.root = File.dirname(__FILE__)
378  
-      assert_equal File.dirname(__FILE__) + "/public", @default.public
  377
+      @application.root = File.dirname(__FILE__)
  378
+      assert_equal File.dirname(__FILE__) + "/public", @application.public
379 379
     end
380 380
   end
381 381
 
6  test/test_test.rb
@@ -114,7 +114,7 @@ def request_params
114 114
   end
115 115
 
116 116
   it 'allow to test session easily' do
117  
-    app = mock_app(Sinatra::Default) {
  117
+    app = mock_app(Sinatra::Base) {
118 118
       get '/' do
119 119
         session['foo'] = 'bar'
120 120
         200
@@ -142,9 +142,9 @@ def request_params
142 142
   end
143 143
 
144 144
   it 'sets the environment to :test on include' do
145  
-    Sinatra::Default.set(:environment, :production)
  145
+    Sinatra::Application.set(:environment, :production)
146 146
     Class.new { include Sinatra::Test }
147  
-    assert_equal :test, Sinatra::Default.environment
  147
+    assert_equal :test, Sinatra::Application.environment
148 148
   end
149 149
 
150 150
   def test_TestHarness

0 notes on commit 7196fa8

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