Skip to content

Commit

Permalink
Deprecate Sinatra::Default; use Sinatra::Application [#240]
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jun 7, 2009
1 parent 578fe06 commit 7f5d4df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 7 additions & 8 deletions lib/sinatra/base.rb
Expand Up @@ -1035,8 +1035,9 @@ def caller_locations
end
end

# Base class for classic style (top-level) applications.
class Default < Base
# The top-level Application. All DSL methods executed on main are delegated
# to this class.
class Application < Base
set :raise_errors, Proc.new { test? }
set :show_exceptions, Proc.new { development? }
set :dump_errors, true
Expand All @@ -1053,10 +1054,8 @@ def self.register(*extensions, &block) #:nodoc:
end
end

# The top-level Application. All DSL methods executed on main are delegated
# to this class.
class Application < Default
end
# Deprecated.
Default = Application

# Sinatra delegation mixin. Mixing this module into an object causes all
# methods to be delegated to the Sinatra::Application class. Used primarily
Expand Down Expand Up @@ -1089,11 +1088,11 @@ 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
12 changes: 6 additions & 6 deletions lib/sinatra/main.rb
@@ -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
Expand All @@ -19,6 +19,11 @@ class Default < Base
op.on('-p port') { |val| set :port, val.to_i }
}.parse!(ARGV.dup)
end

at_exit do
raise $! if $!
run! if run?
end
end
end

Expand All @@ -28,8 +33,3 @@ def mime(ext, type)
ext = ".#{ext}" unless ext.to_s[0] == ?.
Rack::Mime::MIME_TYPES[ext.to_s] = type
end

at_exit do
raise $! if $!
Sinatra::Application.run! if Sinatra::Application.run?
end

2 comments on commit 7f5d4df

@dylanegan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to produce a deprecation warning for people still using Default?

class Default < Application
def initialize(app = nil)
puts "WARNING: Sinatra::Default is deprecated and will be removed in future versions. Please use Sinatra::Application from now on."
super(app)
end
end

@dylanegan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, forgot to tab it. ;)

Please sign in to comment.