lib/usher/node.rb in joshbuddy-usher-0.0.2 vs lib/usher/node.rb in joshbuddy-usher-0.0.3
- old
+ new
@@ -1,8 +1,8 @@
$:.unshift File.dirname(__FILE__)
-require 'node/lookup'
+require 'fuzzy_hash'
class Usher
class Node
@@ -12,11 +12,11 @@
attr_accessor :terminates, :exclusive_type, :parent, :value
def initialize(parent, value)
@parent = parent
@value = value
- @lookup = Lookup.new
+ @lookup = FuzzyHash.new
@exclusive_type = nil
@has_globber = find_parent{|p| p.value && p.value.is_a?(Route::Variable)}
end
def depth
@@ -102,10 +102,11 @@
route
end
def find(request, path = Route::Splitter.url_split(request.path), params = [])
part = path.shift unless path.size.zero?
+
if @exclusive_type
path.unshift part
[@lookup[request.send(@exclusive_type)], @lookup[nil]].each do |n|
ret = n.find(request, path.dup, params.dup) if n
ret and return ret
@@ -124,22 +125,24 @@
when Proc
part = t.call(part)
when Symbol
part = part.send(t)
end
- part =
raise "#{part} does not conform to #{next_part.value.validator}" if next_part.value.validator && (not next_part.value.validator === part)
case next_part.value.type
when :*
params << [next_part.value.name, []]
- params.last.last << part unless next_part.is_a?(Route::Separator)
+ params.last.last << part
when :':'
params << [next_part.value.name, part]
+ when:'.:'
+ part.slice!(0)
+ params << [next_part.value.name, part]
end
end
next_part.find(request, path, params)
- elsif has_globber? && p = find_parent{|p| !p.is_a?(Route::Separator)} && p.value.is_a?(Route::Variable) && p.value.type == :*
- params.last.last << part unless part.is_a?(Route::Separator)
+ elsif has_globber? && p = find_parent{|p| p.value.is_a?(Route::Variable) && p.value.type == :*}
+ params.last.last << part
find(request, path, params)
else
nil
end
end