diff --git a/lib/http_router.rb b/lib/http_router.rb index 68dd495..b815077 100644 --- a/lib/http_router.rb +++ b/lib/http_router.rb @@ -20,10 +20,9 @@ class HttpRouter # Raised when a Route is not able to be generated due to a missing parameter. MissingParameterException = Class.new(RuntimeError) # Raised when a Route is compiled twice - DoubleCompileError = Class.new(RuntimeError) + DoubleCompileError = Class.new(RuntimeError) # Raised an invalid request value is used - InvalidRequestValueError = Class.new(RuntimeError) - + InvalidRequestValueError = Class.new(RuntimeError) # Creates a new HttpRouter. # Can be called with either HttpRouter.new(proc{|env| ... }, { .. options .. }) or with the first argument omitted. diff --git a/lib/http_router/node.rb b/lib/http_router/node.rb index 1065875..e588825 100644 --- a/lib/http_router/node.rb +++ b/lib/http_router/node.rb @@ -69,8 +69,8 @@ def inject_root_methods(code = nil, &blk) code ? root.methods_module.module_eval(code) : root.methods_module.module_eval(&blk) end - def inject_root_ivar(name, val) - root.instance_variable_set(name, val) + def inject_root_ivar(obj) + root.inject_root_ivar(obj) end def add(matcher) diff --git a/lib/http_router/node/lookup.rb b/lib/http_router/node/lookup.rb index 8a1fd98..806c8d8 100644 --- a/lib/http_router/node/lookup.rb +++ b/lib/http_router/node/lookup.rb @@ -15,8 +15,7 @@ def usable?(other) end def to_code - lookup_ivar = :"@lookup_#{root.next_counter}" - inject_root_ivar(lookup_ivar, @map) + lookup_ivar = inject_root_ivar(@map) method_prefix = "lookup_#{root.next_counter} " inject_root_methods @map.keys.map {|k| method = :"#{method_prefix}#{k}" diff --git a/lib/http_router/node/path.rb b/lib/http_router/node/path.rb index 5a2bfa6..efad900 100644 --- a/lib/http_router/node/path.rb +++ b/lib/http_router/node/path.rb @@ -23,8 +23,7 @@ def url(args, options) end def to_code - path_ivar = :"@path_#{root.next_counter}" - inject_root_ivar(path_ivar, self) + path_ivar = inject_root_ivar(self) "#{"if request.path_finished?" unless route.match_partially?} catch(:pass) do #{"if request.path.size == 1 && request.path.first == '' && (request.rack_request.head? || request.rack_request.get?) && request.rack_request.path_info[-1] == ?/ diff --git a/lib/http_router/node/root.rb b/lib/http_router/node/root.rb index 1b9d543..53af40d 100644 --- a/lib/http_router/node/root.rb +++ b/lib/http_router/node/root.rb @@ -22,6 +22,12 @@ def next_counter @counter += 1 end + def inject_root_ivar(obj) + name = :"@ivar_#{@counter += 1}" + root.instance_variable_set(name, obj) + name + end + private def rewrite_partial_path_info(env, request) env['PATH_INFO'] = "/#{request.path.join('/')}"