Permalink
Browse files

deprecate Sinatra::Default

  • Loading branch information...
1 parent 2a8eb72 commit 7196fa83c52168106c10c8010236563622497af2 @rtomayko rtomayko committed Mar 4, 2010
View
@@ -11,6 +11,11 @@
* New 'settings' method gives access to options in both class and request
scopes. This replaces the 'options' method. (Chris Wanstrath)
+ * `Sinatra::Default` is obsolete; use `Sinatra::Base` instead.
+ `Sinatra::Base` acts more like `Sinatra::Default` in development mode.
+ For example, static file serving and sexy development error pages are
+ enabled by default.
+
* The `:methodoverride' option to enable/disable the POST _method hack is
obsolete; use `:method_override` instead.
View
@@ -1084,32 +1084,41 @@ class << self
# Sinatra::Base instead and set options as needed.
class Default < Base
set :raise_errors, Proc.new { test? }
- set :show_exceptions, Proc.new { development? }
set :dump_errors, true
set :sessions, false
set :logging, Proc.new { ! test? }
set :method_override, true
set :run, Proc.new { ! test? }
set :static, true
- def self.register(*extensions, &block) #:nodoc:
- added_methods = extensions.map {|m| m.public_instance_methods }.flatten
- Delegator.delegate(*added_methods)
- super(*extensions, &block)
- end
-
def self.inherited(subclass)
- if subclass.to_s != 'Sinatra::Application'
- sinatra_warn 'Sinatra::Default is deprecated;' +
- ' subclass Sinatra::Base instead'
- end
+ sinatra_warn 'Sinatra::Default is deprecated; ' \
+ 'subclass Sinatra::Base instead'
super
end
end
- # The top-level Application. All DSL methods executed on main are delegated
- # to this class.
- class Application < Default
+ # Execution context for classic style (top-level) applications. All
+ # DSL methods executed on main are delegated to this class.
+ #
+ # The Application class should not be subclassed, unless you want to
+ # inherit all settings, routes, handlers, and error pages from the
+ # top-level. Subclassing Sinatra::Base is heavily recommended for
+ # modular applications.
+ class Application < Base
+ set :raise_errors, Proc.new { test? }
+ set :dump_errors, true
+ set :sessions, false
+ set :logging, Proc.new { ! test? }
+ set :method_override, true
+ set :run, Proc.new { ! test? }
+ set :static, true
+
+ def self.register(*extensions, &block) #:nodoc:
+ added_methods = extensions.map {|m| m.public_instance_methods }.flatten
+ Delegator.delegate(*added_methods)
+ super(*extensions, &block)
+ end
end
# Sinatra delegation mixin. Mixing this module into an object causes all
@@ -1143,12 +1152,12 @@ def self.new(base=Base, options={}, &block)
# Extend the top-level DSL with the modules provided.
def self.register(*extensions, &block)
- Default.register(*extensions, &block)
+ Application.register(*extensions, &block)
end
# Include the helper modules provided in Sinatra's request context.
def self.helpers(*extensions, &block)
- Default.helpers(*extensions, &block)
+ Application.helpers(*extensions, &block)
end
end
@@ -45,7 +45,7 @@ module Sinatra
module Compat #:nodoc:
end
- # Make Sinatra::EventContext an alias for Sinatra::Default to unbreak plugins.
+ # Make Sinatra::EventContext an alias for Sinatra::Application to unbreak plugins.
def self.const_missing(const_name) #:nodoc:
if const_name == :EventContext
const_set :EventContext, Sinatra::Application
View
@@ -1,7 +1,7 @@
require 'sinatra/base'
module Sinatra
- class Default < Base
+ class Application < Base
# we assume that the first file that requires 'sinatra' is the
# app_file. all other path related options are calculated based
View
@@ -7,7 +7,7 @@ module Test
include Rack::Utils
def self.included(base)
- Sinatra::Default.set(:environment, :test)
+ Sinatra::Application.set(:environment, :test)
end
attr_reader :app, :request, :response
@@ -3,7 +3,7 @@
Sinatra::Test.deprecate('Bacon')
-Sinatra::Default.set(
+Sinatra::Application.set(
:environment => :test,
:run => false,
:raise_errors => true,
@@ -5,7 +5,7 @@
Sinatra::Test.deprecate('RSpec')
-Sinatra::Default.set(
+Sinatra::Application.set(
:environment => :test,
:run => false,
:raise_errors => true,
@@ -5,7 +5,7 @@
Test::Unit::TestCase.send :include, Sinatra::Test
-Sinatra::Default.set(
+Sinatra::Application.set(
:environment => :test,
:run => false,
:raise_errors => true,
@@ -35,9 +35,9 @@ def fizz!(name); end
Sinatra::Base.register FooExtensions
assert Sinatra::Base.respond_to?(:foo)
- Sinatra::Default.register BarExtensions
- assert Sinatra::Default.respond_to?(:bar)
- assert Sinatra::Default.respond_to?(:foo)
+ Sinatra::Application.register BarExtensions
+ assert Sinatra::Application.respond_to?(:bar)
+ assert Sinatra::Application.respond_to?(:foo)
assert !Sinatra::Base.respond_to?(:bar)
end
@@ -48,16 +48,16 @@ def im_in_ur_anonymous_module; end
assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
end
- it 'will make sure any public methods added via Default#register are delegated to Sinatra::Delegator' do
- Sinatra::Default.register FooExtensions
+ it 'will make sure any public methods added via Application#register are delegated to Sinatra::Delegator' do
+ Sinatra::Application.register FooExtensions
assert Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:foo)
assert !Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:im_hiding_in_ur_foos)
end
it 'will handle special method names' do
- Sinatra::Default.register PainExtensions
+ Sinatra::Application.register PainExtensions
assert Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:foo=)
assert Sinatra::Delegator.private_instance_methods.
@@ -71,10 +71,10 @@ def im_in_ur_anonymous_module; end
assert !Sinatra::Delegator.private_instance_methods.include?("quux")
end
- it 'will extend the Sinatra::Default application by default' do
+ it 'will extend the Sinatra::Application by default' do
Sinatra.register BazExtensions
assert !Sinatra::Base.respond_to?(:baz)
- assert Sinatra::Default.respond_to?(:baz)
+ assert Sinatra::Application.respond_to?(:baz)
end
module BizzleExtension
@@ -2,7 +2,7 @@
class MiddlewareTest < Test::Unit::TestCase
setup do
- @app = mock_app(Sinatra::Default) {
+ @app = mock_app(Sinatra::Base) {
get '/*' do
response.headers['X-Tests'] = env['test.ran'].
map { |n| n.split('::').last }.
Oops, something went wrong. Retry.

0 comments on commit 7196fa8

Please sign in to comment.