Skip to content

Commit

Permalink
slight cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy committed Jul 25, 2011
1 parent 5ec36f9 commit 7d3ec45
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
5 changes: 2 additions & 3 deletions lib/http_router.rb
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/http_router/node.rb
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions lib/http_router/node/lookup.rb
Expand Up @@ -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}"
Expand Down
3 changes: 1 addition & 2 deletions lib/http_router/node/path.rb
Expand Up @@ -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] == ?/
Expand Down
6 changes: 6 additions & 0 deletions lib/http_router/node/root.rb
Expand Up @@ -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('/')}"
Expand Down

0 comments on commit 7d3ec45

Please sign in to comment.