Permalink
Browse files

move counter to root

  • Loading branch information...
1 parent ee60fb5 commit 8dafa01e043af5e31d71ed4586f9d3a8d9600e38 @joshbuddy committed Jul 23, 2011
View
@@ -40,7 +40,6 @@ def initialize(*args, &blk)
@ignore_trailing_slash = options && options.key?(:ignore_trailing_slash) ? options[:ignore_trailing_slash] : true
@redirect_trailing_slash = options && options.key?(:redirect_trailing_slash) ? options[:redirect_trailing_slash] : false
@known_methods = Set.new(options && options[:known_methods] || [])
- @counter = 0
reset!
instance_eval(&blk) if blk
end
@@ -63,7 +62,6 @@ def initialize(*args, &blk)
def add(path, opts = {}, &app)
route = add_route((Regexp === path ? RegexRoute : Route).new(self, path, opts))
route.to(app) if app
- root.uncompile
route
end
@@ -201,10 +199,6 @@ def clone(klass = self.class)
cloned_router
end
- def next_counter
- @counter += 1
- end
-
private
def no_response(env, perform_call = true)
supported_methods = @known_methods.select do |m|
@@ -13,7 +13,7 @@ def usable?(other)
end
def to_code
- b, method_name = @blk, :"blk_#{router.next_counter}"
+ b, method_name = @blk, :"blk_#{root.next_counter}"
inject_root_methods { define_method(method_name) { b } }
"#{"if request.path_finished?" unless @allow_partial}
request.continue = proc { |state|
@@ -15,9 +15,9 @@ def usable?(other)
end
def to_code
- lookup_ivar = :"@lookup_#{router.next_counter}"
+ lookup_ivar = :"@lookup_#{root.next_counter}"
inject_root_ivar(lookup_ivar, @map)
- method_prefix = "lookup_#{router.next_counter} "
+ method_prefix = "lookup_#{root.next_counter} "
inject_root_methods @map.keys.map {|k|
method = :"#{method_prefix}#{k}"
"define_method(#{method.inspect}) do |request|
@@ -8,6 +8,7 @@ def initialize(router, parent, route, path, param_names = [])
raise AmbiguousVariableException, "You have duplicate variable name present: #{param_names.join(', ')}" if param_names.uniq.size != param_names.size
process_path_for_generation(@original_path) if @original_path.respond_to?(:split)
super router, parent
+ root.uncompile
end
def hashify_params(params)
@@ -22,7 +23,7 @@ def url(args, options)
end
def to_code
- path_ivar = :"@path_#{router.next_counter}"
+ path_ivar = :"@path_#{root.next_counter}"
inject_root_ivar(path_ivar, self)
"#{"if request.path_finished?" unless route.match_partially?}
catch(:pass) do
@@ -5,7 +5,7 @@ class Root < Node
alias_method :compiled?, :compiled
def initialize(router)
super(router, nil)
- @methods_module = Module.new
+ @counter, @methods_module = 0, Module.new
end
def [](request)
@@ -18,6 +18,10 @@ def uncompile
instance_eval "undef :[]; alias :[] :compiling_lookup", __FILE__, __LINE__ if compiled?
end
+ def next_counter
+ @counter += 1
+ end
+
private
def compile
root.extend(root.methods_module)

0 comments on commit 8dafa01

Please sign in to comment.