Merge branch 'obsolete-default'

This commit is contained in:
Ryan Tomayko 2010-01-28 11:46:00 -08:00
commit 186a5bc9b6
4 changed files with 41 additions and 22 deletions

View File

@ -1023,15 +1023,14 @@ module Sinatra
reset!
set :raise_errors, true
set :dump_errors, false
set :environment, (ENV['RACK_ENV'] || :development).to_sym
set :raise_errors, Proc.new { !development? }
set :dump_errors, Proc.new { development? }
set :show_exceptions, Proc.new { development? }
set :clean_trace, true
set :show_exceptions, false
set :sessions, false
set :logging, false
set :methodoverride, false
set :static, false
set :environment, (ENV['RACK_ENV'] || :development).to_sym
set :run, false # start server via at-exit hook?
set :running, false # is the built-in server running now?
@ -1041,11 +1040,13 @@ module Sinatra
set :app_file, nil
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
set :public, Proc.new { root && File.join(root, 'public') }
set :views, Proc.new { root && File.join(root, 'views') }
set :reload_templates, Proc.new { !development? }
set :lock, false
set :public, Proc.new { root && File.join(root, 'public') }
set :static, Proc.new { self.public && File.exist?(self.public) }
error ::Exception do
response.status = 500
content_type 'text/html'
@ -1086,16 +1087,21 @@ module Sinatra
end
end
# Base class for classic style (top-level) applications.
class Default < Base
# 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 :show_exceptions, Proc.new { development? }
set :dump_errors, true
set :sessions, false
set :logging, Proc.new { ! test? }
set :methodoverride, true
set :static, 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
@ -1104,11 +1110,6 @@ module Sinatra
end
end
# The top-level Application. All DSL methods executed on main are delegated
# to this class.
class Application < Default
end
# Sinatra delegation mixin. Mixing this module into an object causes all
# methods to be delegated to the Sinatra::Application class. Used primarily
# at the top-level.
@ -1140,11 +1141,11 @@ module Sinatra
# 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

View File

@ -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

0
test/public/favicon.ico Normal file
View File

View File

@ -177,8 +177,10 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'raise_errors' do
it 'is enabled on Base' do
it 'is enabled on Base except under development' do
assert @base.raise_errors?
@base.environment = :development
assert !@base.raise_errors?
end
it 'is enabled on Application only in test' do
@ -190,8 +192,10 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'show_exceptions' do
it 'is disabled on Base' do
it 'is disabled on Base except under development' do
assert ! @base.show_exceptions?
@base.environment = :development
assert @base.show_exceptions?
end
it 'is disabled on Application except in development' do
@ -219,8 +223,10 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'dump_errors' do
it 'is disabled on Base' do
it 'is disabled on Base except in development' do
assert ! @base.dump_errors?
@base.environment = :development
assert @base.dump_errors?
end
it 'is enabled on Application' do
@ -274,10 +280,22 @@ class SettingsTest < Test::Unit::TestCase
end
describe 'static' do
it 'is disabled on Base' do
it 'is disabled on Base by default' do
assert ! @base.static?
end
it 'is enabled on Base when public is set and exists' do
@base.set :environment, :development
@base.set :public, File.dirname(__FILE__)
assert @base.static?
end
it 'is enabled on Base when root is set and root/public exists' do
@base.set :environment, :development
@base.set :root, File.dirname(__FILE__)
assert @base.static?
end
it 'is enabled on Application' do
assert @application.static?
end