Permalink
Browse files

slight cleanup

  • Loading branch information...
1 parent 5ec36f9 commit 7d3ec45712af4a79ddd1e1cf06f3c46d8bd88948 @joshbuddy committed Jul 25, 2011
View
@@ -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 <tt>HttpRouter.new(proc{|env| ... }, { .. options .. })</tt> or with the first argument omitted.
View
@@ -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)
@@ -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}"
@@ -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] == ?/
@@ -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('/')}"

0 comments on commit 7d3ec45

Please sign in to comment.