Skip to content
Browse files

one-line compile/uncompile

  • Loading branch information...
1 parent a2b414f commit adf5bb398d077eff903dbda01533207289551d36 @joshbuddy committed Sep 7, 2011
Showing with 3 additions and 4 deletions.
  1. +3 −4 lib/http_router.rb
View
7 lib/http_router.rb
@@ -112,6 +112,7 @@ def call(env, perform_call = true)
# Resets the router to a clean state.
def reset!
+ @compiled = false
uncompile
@routes, @named_routes, @root = [], Hash.new{|h,k| h[k] = []}, Node::Root.new(self)
@default_app = Proc.new{ |env| ::Rack::Response.new("Your request couldn't be found", 404).finish }
@@ -209,15 +210,13 @@ def inspect
def compile
return if @compiled
@routes.each {|r| r.send(:compile)}
- instance_eval "undef :url; alias :url :raw_url", __FILE__, __LINE__
- instance_eval "undef :call; alias :call :raw_call", __FILE__, __LINE__
+ instance_eval "undef :url; alias :url :raw_url; undef :call; alias :call :raw_call", __FILE__, __LINE__
@compiled = true
end
def uncompile
return unless @compiled
- instance_eval "undef :url; alias :url :compiling_url", __FILE__, __LINE__
- instance_eval "undef :call; alias :call :compiling_call", __FILE__, __LINE__
+ instance_eval "undef :url; alias :url :compiling_url; undef :call; alias :call :compiling_call", __FILE__, __LINE__
@compiled = false
end

0 comments on commit adf5bb3

Please sign in to comment.
Something went wrong with that request. Please try again.