joshbuddy-usher 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/usher/node.rb +32 -8
- data/lib/usher/splitter.rb +1 -2
- data/spec/{generate_spec.rb → private/generate_spec.rb} +0 -0
- data/spec/{grapher_spec.rb → private/grapher_spec.rb} +0 -0
- data/spec/{path_spec.rb → private/path_spec.rb} +0 -0
- data/spec/{rack → private/rack}/dispatch_spec.rb +0 -0
- data/spec/{rails → private/rails}/compat.rb +0 -0
- data/spec/{rails → private/rails}/generate_spec.rb +0 -0
- data/spec/{rails → private/rails}/path_spec.rb +0 -0
- data/spec/{rails → private/rails}/recognize_spec.rb +0 -0
- data/spec/{recognize_spec.rb → private/recognize_spec.rb} +14 -1
- data/spec/{request_method_spec.rb → private/request_method_spec.rb} +0 -0
- data/spec/{split_spec.rb → private/split_spec.rb} +0 -0
- metadata +15 -14
data/VERSION.yml
CHANGED
data/lib/usher/node.rb
CHANGED
@@ -107,18 +107,42 @@ class Usher
|
|
107
107
|
end
|
108
108
|
elsif next_part = @lookup[part]
|
109
109
|
if next_part.value.is_a?(Route::Variable)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
case next_part.value.type
|
111
|
+
when :*
|
112
|
+
params << [next_part.value.name, []] unless params.last && params.last.first == next_part.value.name
|
113
|
+
loop do
|
114
|
+
if (next_part.value.look_ahead === part || (!part.is_a?(Symbol) && !next_part.value.regex_matcher.match(part)))
|
115
|
+
path.unshift(part)
|
116
|
+
path.unshift(next_part.parent.value) if next_part.parent.value.is_a?(Symbol)
|
117
|
+
break
|
118
|
+
else
|
119
|
+
unless part.is_a?(Symbol)
|
120
|
+
part = next_part.value.transform!(part)
|
121
|
+
next_part.value.valid!(part)
|
122
|
+
params.last.last << part
|
123
|
+
end
|
124
|
+
end
|
125
|
+
if path.size.zero?
|
126
|
+
break
|
127
|
+
else
|
128
|
+
part = path.shift
|
129
|
+
end
|
130
|
+
end
|
131
|
+
next_part.find(request, path, params)
|
132
|
+
when :':'
|
133
|
+
part = next_part.value.transform!(part)
|
134
|
+
next_part.value.valid!(part)
|
135
|
+
var = next_part.value
|
136
|
+
params << [next_part.value.name, part]
|
137
|
+
until (path.first == var.look_ahead) || path.empty?
|
138
|
+
params.last.last << path.shift.to_s
|
139
|
+
end
|
140
|
+
next_part.find(request, path, params)
|
116
141
|
end
|
117
|
-
next_part.find(request, path, params)
|
118
142
|
else
|
119
143
|
next_part.find(request, path, params)
|
120
144
|
end
|
121
|
-
elsif next_part = @lookup[
|
145
|
+
elsif next_part = @lookup[nil]
|
122
146
|
if next_part.value.is_a?(Route::Variable)
|
123
147
|
case next_part.value.type
|
124
148
|
when :*
|
data/lib/usher/splitter.rb
CHANGED
@@ -53,7 +53,7 @@ class Usher
|
|
53
53
|
when ?{
|
54
54
|
pattern = ''
|
55
55
|
count = 1
|
56
|
-
variable = ss.scan(
|
56
|
+
variable = ss.scan(/[:\*]([^,]+),/)
|
57
57
|
until count.zero?
|
58
58
|
regex_part = ss.scan(/\{|\}|[^\{\}]+/)
|
59
59
|
case regex_part[0]
|
@@ -73,7 +73,6 @@ class Usher
|
|
73
73
|
else
|
74
74
|
current_group << regex
|
75
75
|
end
|
76
|
-
|
77
76
|
when ?(
|
78
77
|
new_group = Group.new(:any, current_group)
|
79
78
|
current_group << new_group
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -61,7 +61,7 @@ describe "Usher route recognition" do
|
|
61
61
|
route_set.recognize(build_request({:method => 'get', :path => '/test/part/oooo'})).should == nil
|
62
62
|
end
|
63
63
|
|
64
|
-
it "should recgonize a regex
|
64
|
+
it "should recgonize a regex single variable" do
|
65
65
|
target_route = route_set.add_route('/test/part/{:test,hello|again}')
|
66
66
|
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello'})).path.route.should == target_route
|
67
67
|
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello'})).params.should == [[:test, 'hello']]
|
@@ -70,6 +70,19 @@ describe "Usher route recognition" do
|
|
70
70
|
route_set.recognize(build_request({:method => 'get', :path => '/test/part/world'})).should == nil
|
71
71
|
end
|
72
72
|
|
73
|
+
it "should recgonize a regex glob variable" do
|
74
|
+
target_route = route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}')
|
75
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again'})).path.route.should == target_route
|
76
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']]]
|
77
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/agaim/123/hello/again'})).should == nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should recgonize a regex glob variable terminated by a static part" do
|
81
|
+
target_route = route_set.add_route('/test/part/{*test,^(hello|again|\d+)$}/onemore')
|
82
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).path.route.should == target_route
|
83
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']]]
|
84
|
+
end
|
85
|
+
|
73
86
|
it "should recgonize two glob-style variables separated by a static part" do
|
74
87
|
target_route = route_set.add_route('/*format/innovate/*onemore')
|
75
88
|
response = route_set.recognize(build_request({:method => 'get', :path => '/sample/html/innovate/apple'}))
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joshbuddy-usher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -57,20 +57,21 @@ files:
|
|
57
57
|
- lib/usher/route.rb
|
58
58
|
- lib/usher/splitter.rb
|
59
59
|
- lib/usher.rb
|
60
|
-
- spec/
|
61
|
-
- spec/
|
62
|
-
- spec/
|
63
|
-
- spec/
|
64
|
-
- spec/rack
|
65
|
-
- spec/
|
66
|
-
- spec/rails
|
67
|
-
- spec/rails/
|
68
|
-
- spec/rails/
|
69
|
-
- spec/rails/
|
70
|
-
- spec/recognize_spec.rb
|
71
|
-
- spec/
|
60
|
+
- spec/private
|
61
|
+
- spec/private/generate_spec.rb
|
62
|
+
- spec/private/grapher_spec.rb
|
63
|
+
- spec/private/path_spec.rb
|
64
|
+
- spec/private/rack
|
65
|
+
- spec/private/rack/dispatch_spec.rb
|
66
|
+
- spec/private/rails
|
67
|
+
- spec/private/rails/compat.rb
|
68
|
+
- spec/private/rails/generate_spec.rb
|
69
|
+
- spec/private/rails/path_spec.rb
|
70
|
+
- spec/private/rails/recognize_spec.rb
|
71
|
+
- spec/private/recognize_spec.rb
|
72
|
+
- spec/private/request_method_spec.rb
|
73
|
+
- spec/private/split_spec.rb
|
72
74
|
- spec/spec.opts
|
73
|
-
- spec/split_spec.rb
|
74
75
|
- rails/init.rb
|
75
76
|
has_rdoc: true
|
76
77
|
homepage: http://github.com/joshbuddy/usher
|