1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Cleanup and refactoring after inheritance changes

This commit is contained in:
Ryan Tomayko 2009-03-26 10:26:09 -07:00
parent f974af4c03
commit f75bee5acd
2 changed files with 34 additions and 28 deletions

View file

@ -1,3 +1,12 @@
= 1.0 / unreleased
* Route handlers, before filters, templates, error mappings, and
middleware are now resolved dynamically up the inheritance hierarchy
when needed instead of duplicating the superclass's version when
a new Sinatra::Base subclass is created. This should fix a variety
of issues with extensions that need to add any of these things
to the base class.
= 0.9.2 / 2009-05-18
* This version is compatible with Rack 1.0. [Rein Henrichs]

View file

@ -606,17 +606,28 @@ module Sinatra
}.map! { |line| line.gsub(/^\.\//, '') }
end
@routes = {}
@filters = []
@conditions = []
@templates = {}
@middleware = []
@errors = {}
@prototype = nil
@extensions = []
class << self
attr_accessor :routes, :filters, :conditions, :templates, :errors
attr_reader :routes, :filters, :templates, :errors
def reset!
@conditions = []
@routes = {}
@filters = []
@templates = {}
@errors = {}
@middleware = []
@prototype = nil
@extensions = []
end
# Extension modules registered on this class and all superclasses.
def extensions
if superclass.respond_to?(:extensions)
(@extensions + superclass.extensions).uniq
else
@extensions
end
end
# Middleware used in this class and all superclasses.
def middleware
@ -793,7 +804,7 @@ module Sinatra
invoke_hook(:route_added, verb, path, block)
(routes[verb] ||= []).
(@routes[verb] ||= []).
push([pattern, keys, conditions, block]).last
end
@ -836,10 +847,6 @@ module Sinatra
include(*extensions) if extensions.any?
end
def extensions
(@extensions + (superclass.extensions rescue [])).uniq
end
def register(*extensions, &block)
extensions << Module.new(&block) if block_given?
@extensions += extensions
@ -898,7 +905,6 @@ module Sinatra
builder.use Rack::CommonLogger if logging?
builder.use Rack::MethodOverride if methodoverride?
builder.use ShowExceptions if show_exceptions?
middleware.each { |c,a,b| builder.use(c, *a, &b) }
builder.run super
@ -909,17 +915,6 @@ module Sinatra
synchronize { prototype.call(env) }
end
def reset!(base=superclass)
@routes = {}
@templates = {}
@conditions = []
@filters = []
@errors = {}
@middleware = []
@prototype = nil
@extensions = []
end
private
def detect_rack_handler
servers = Array(self.server)
@ -934,7 +929,7 @@ module Sinatra
end
def inherited(subclass)
subclass.reset! self
subclass.reset!
super
end
@ -977,6 +972,8 @@ module Sinatra
end
end
reset!
set :raise_errors, true
set :dump_errors, false
set :clean_trace, true