31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/usher/route/util.rb', line 31
def self.expand_path(parts)
if parts.is_a?(Array)
paths = [[]]
unless parts.respond_to?(:group_type)
new_parts = Group.new(:any, nil)
parts.each{|p| new_parts << p}
parts = new_parts
end
case parts.group_type
when :all
parts.each do |p|
cartesian_product!(paths, expand_path(p))
end
when :any
parts.each do |p|
cartesian_product!(paths, expand_path(p))
end
paths.unshift([])
when :one
cartesian_product!(paths, parts.collect do |p|
expand_path(p)
end)
end
paths.each{|p| p.compact!; p.flatten! }
paths
else
[[parts]]
end
end
|