Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup and refactoring after inheritance changes

  • Loading branch information...
commit f75bee5acdc9a2da14e3605b49f6b61f94da7fa8 1 parent f974af4
@rtomayko rtomayko authored
Showing with 34 additions and 28 deletions.
  1. +9 −0 CHANGES
  2. +25 −28 lib/sinatra/base.rb
View
9 CHANGES
@@ -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
53 lib/sinatra/base.rb
@@ -606,17 +606,28 @@ def clean_backtrace(trace)
}.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 @@ def route(verb, path, options={}, &block)
invoke_hook(:route_added, verb, path, block)
- (routes[verb] ||= []).
+ (@routes[verb] ||= []).
push([pattern, keys, conditions, block]).last
end
@@ -836,10 +847,6 @@ def helpers(*extensions, &block)
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 @@ def new(*args, &bk)
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 @@ def call(env)
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 @@ def detect_rack_handler
end
def inherited(subclass)
- subclass.reset! self
+ subclass.reset!
super
end
@@ -977,6 +972,8 @@ def caller_locations
end
end
+ reset!
+
set :raise_errors, true
set :dump_errors, false
set :clean_trace, true
Please sign in to comment.
Something went wrong with that request. Please try again.