usher 0.5.13 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +16 -0
- data/Rakefile +1 -1
- data/VERSION.yml +3 -3
- data/lib/usher.rb +31 -9
- data/lib/usher/delimiters.rb +16 -14
- data/lib/usher/grapher.rb +45 -22
- data/lib/usher/interface.rb +8 -4
- data/lib/usher/interface/sinatra.rb +66 -0
- data/lib/usher/node.rb +9 -1
- data/lib/usher/route.rb +45 -12
- data/lib/usher/route/path.rb +11 -2
- data/lib/usher/route/static.rb +1 -1
- data/lib/usher/util/generate.rb +6 -4
- data/lib/usher/util/parser.rb +133 -142
- data/spec/private/delimiters_spec.rb +5 -5
- data/spec/private/destination_spec.rb +32 -0
- data/spec/private/generate_spec.rb +28 -0
- data/spec/private/generate_with_spec.rb +2 -2
- data/spec/private/rack/dispatch_spec.rb +38 -1
- data/spec/private/recognize_spec.rb +27 -0
- data/spec/private/url_parts_spec.rb +4 -4
- metadata +6 -6
- data/lib/usher/spinoffs/strscan_additions.rb +0 -31
- data/spec/private/string_scanner_spec.rb +0 -39
@@ -3,7 +3,7 @@ require "usher"
|
|
3
3
|
|
4
4
|
describe Usher::Route::GenerateWith, "#empty?" do
|
5
5
|
before :all do
|
6
|
-
GenerateWith = Usher::Route::GenerateWith
|
6
|
+
::GenerateWith = Usher::Route::GenerateWith
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "when all fields are nil" do
|
@@ -25,4 +25,4 @@ describe Usher::Route::GenerateWith, "#empty?" do
|
|
25
25
|
@filled_generate_with.empty?.should be_false
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -84,6 +84,12 @@ describe "Usher (for rack) route dispatching" do
|
|
84
84
|
@usher2.add("/bad" ).match_partially!.to(@bad_app)
|
85
85
|
@usher2.add("/some(/:foo)").to(@app)
|
86
86
|
|
87
|
+
@usher3 = Usher::Interface.for(:rack)
|
88
|
+
@usher3.add("(/)", :default_values => {:optional_root => true} ).to(@app)
|
89
|
+
|
90
|
+
@usher2.add("/optional_mount").match_partially!.to(@usher3)
|
91
|
+
|
92
|
+
route_set.add("/baz", :default_values => {:baz => "baz"}).match_partially!.to(@usher3)
|
87
93
|
route_set.add("/foo/:bar", :default_values => {:foo => "foo"}).match_partially!.to(@usher2)
|
88
94
|
route_set.add("/foo", :default_values => {:controller => :foo}).to(@app)
|
89
95
|
end
|
@@ -93,6 +99,37 @@ describe "Usher (for rack) route dispatching" do
|
|
93
99
|
route_set.call(Rack::MockRequest.env_for("/foo"))
|
94
100
|
end
|
95
101
|
|
102
|
+
it "should match the route where the last part is optional" do
|
103
|
+
@app.should_receive(:call).once.with do |e|
|
104
|
+
e['usher.params'].should == {
|
105
|
+
:optional_root => true,
|
106
|
+
:baz => 'baz'
|
107
|
+
}
|
108
|
+
end
|
109
|
+
route_set.call(Rack::MockRequest.env_for("/baz/"))
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should match when a mounted apps root route is optional" do
|
113
|
+
@app.should_receive(:call).once.with do |e|
|
114
|
+
e['usher.params'].should == {
|
115
|
+
:optional_root => true,
|
116
|
+
:foo => "foo",
|
117
|
+
:bar => "bar"
|
118
|
+
}
|
119
|
+
end
|
120
|
+
route_set.call(Rack::MockRequest.env_for("/foo/bar/optional_mount"))
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should match the route where the last part is empty" do
|
124
|
+
@app.should_receive(:call).once.with do |e|
|
125
|
+
e['usher.params'].should == {
|
126
|
+
:baz => 'baz',
|
127
|
+
:optional_root => true
|
128
|
+
}
|
129
|
+
end
|
130
|
+
route_set.call(Rack::MockRequest.env_for("/baz"))
|
131
|
+
end
|
132
|
+
|
96
133
|
it "should route through the first route, and the second to the app" do
|
97
134
|
@app.should_receive(:call).once.with{|e| e['usher.params'].should == {:bar => "bar", :foo => "foo"}}
|
98
135
|
result = route_set.call(Rack::MockRequest.env_for("/foo/bar/good"))
|
@@ -195,7 +232,7 @@ describe "Usher (for rack) route dispatching" do
|
|
195
232
|
end
|
196
233
|
end
|
197
234
|
end
|
198
|
-
|
235
|
+
|
199
236
|
describe "use as middlware" do
|
200
237
|
it "should allow me to set a default application to use" do
|
201
238
|
@app.should_receive(:call).with{|e| e['usher.params'].should == {:middle => :ware}}
|
@@ -47,6 +47,23 @@ describe "Usher route recognition" do
|
|
47
47
|
@route_set.recognize(build_request({:method => 'put', :path => '/sample', :protocol => 'wacky', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_http_admin_generic
|
48
48
|
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should recognize an empty path" do
|
52
|
+
@route_set.add_route('').to(:test)
|
53
|
+
@route_set.recognize(build_request({:path => ''})).path.route.destination.should == :test
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should recognize an optionally empty path" do
|
57
|
+
@route_set.add_route('(/)').to(:test)
|
58
|
+
@route_set.recognize(build_request({:path => ''})).path.route.destination.should == :test
|
59
|
+
@route_set.recognize(build_request({:path => '/'})).path.route.destination.should == :test
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow adding a pure regex" do
|
63
|
+
@route_set.add_route(/\/test\/(testing|gold)/).to(:test)
|
64
|
+
@route_set.recognize(build_request({:path => '/test/testing'})).path.route.destination.should == :test
|
65
|
+
@route_set.recognize(build_request({:path => '/test/gold'})).path.route.destination.should == :test
|
66
|
+
end
|
50
67
|
|
51
68
|
it "should correctly fix that tree if conditionals are used later" do
|
52
69
|
noop_route = @route_set.add_route('/noop', :controller => 'products', :action => 'noop')
|
@@ -73,6 +90,15 @@ describe "Usher route recognition" do
|
|
73
90
|
end
|
74
91
|
end
|
75
92
|
|
93
|
+
it "should recognize path with a trailing slash" do
|
94
|
+
@route_set = Usher.new(:request_methods => [:protocol, :domain, :port, :query_string, :remote_ip, :user_agent, :referer, :method, :subdomains], :ignore_trailing_delimiters => true)
|
95
|
+
|
96
|
+
target_route = @route_set.add_route('/path', :controller => 'sample', :action => 'action')
|
97
|
+
|
98
|
+
response = @route_set.recognize(build_request({:method => 'get', :path => '/path/'}))
|
99
|
+
response.path.route.should == target_route
|
100
|
+
end
|
101
|
+
|
76
102
|
it "should recognize a format-style variable" do
|
77
103
|
target_route = @route_set.add_route('/sample.:format', :controller => 'sample', :action => 'action')
|
78
104
|
@route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:format , 'html']], nil, "/sample.html")
|
@@ -368,4 +394,5 @@ describe "Usher route recognition" do
|
|
368
394
|
end
|
369
395
|
|
370
396
|
end
|
397
|
+
|
371
398
|
end
|
@@ -28,11 +28,11 @@ describe Usher::Util::Generators::URL::UrlParts do
|
|
28
28
|
include PathAndRequestHelper
|
29
29
|
|
30
30
|
before :all do
|
31
|
-
UrlParts = Usher::Util::Generators::URL::UrlParts
|
31
|
+
::UrlParts = Usher::Util::Generators::URL::UrlParts
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "#url" do
|
35
|
-
describe "when generate_with is provided" do
|
35
|
+
describe "when generate_with is provided" do
|
36
36
|
before :each do
|
37
37
|
@path = stub_path_with 'https', 'overridden', 9443
|
38
38
|
@request = rack_request_for 'http://localhost'
|
@@ -105,7 +105,7 @@ describe Usher::Util::Generators::URL::UrlParts do
|
|
105
105
|
@request = mock 'request'
|
106
106
|
end
|
107
107
|
|
108
|
-
it "should just extract the url" do
|
108
|
+
it "should just extract the url" do
|
109
109
|
@request.should_receive(:url).and_return('http://localhost')
|
110
110
|
|
111
111
|
url_parts = UrlParts.new(@path, @request)
|
@@ -113,4 +113,4 @@ describe Usher::Util::Generators::URL::UrlParts do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
116
|
-
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2009-12-
|
17
|
+
date: 2009-12-13 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.0.
|
28
|
+
version: 0.0.11
|
29
29
|
version:
|
30
30
|
description: A general purpose routing library
|
31
31
|
email: joshbuddy@gmail.com
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/usher/interface/rails23.rb
|
58
58
|
- lib/usher/interface/rails23/mapper.rb
|
59
59
|
- lib/usher/interface/rails3.rb
|
60
|
+
- lib/usher/interface/sinatra.rb
|
60
61
|
- lib/usher/interface/text.rb
|
61
62
|
- lib/usher/node.rb
|
62
63
|
- lib/usher/route.rb
|
@@ -65,7 +66,6 @@ files:
|
|
65
66
|
- lib/usher/route/static.rb
|
66
67
|
- lib/usher/route/util.rb
|
67
68
|
- lib/usher/route/variable.rb
|
68
|
-
- lib/usher/spinoffs/strscan_additions.rb
|
69
69
|
- lib/usher/splitter.rb
|
70
70
|
- lib/usher/util.rb
|
71
71
|
- lib/usher/util/generate.rb
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/usher/util/rack-mixins.rb
|
75
75
|
- rails/init.rb
|
76
76
|
- spec/private/delimiters_spec.rb
|
77
|
+
- spec/private/destination_spec.rb
|
77
78
|
- spec/private/email/recognize_spec.rb
|
78
79
|
- spec/private/generate_spec.rb
|
79
80
|
- spec/private/generate_with_spec.rb
|
@@ -94,7 +95,6 @@ files:
|
|
94
95
|
- spec/private/recognize_spec.rb
|
95
96
|
- spec/private/request_method_spec.rb
|
96
97
|
- spec/private/splitter_spec.rb
|
97
|
-
- spec/private/string_scanner_spec.rb
|
98
98
|
- spec/private/url_parts_spec.rb
|
99
99
|
- spec/spec.opts
|
100
100
|
- spec/spec_helper.rb
|
@@ -128,6 +128,7 @@ specification_version: 3
|
|
128
128
|
summary: A general purpose routing library
|
129
129
|
test_files:
|
130
130
|
- spec/private/delimiters_spec.rb
|
131
|
+
- spec/private/destination_spec.rb
|
131
132
|
- spec/private/email/recognize_spec.rb
|
132
133
|
- spec/private/generate_spec.rb
|
133
134
|
- spec/private/generate_with_spec.rb
|
@@ -148,6 +149,5 @@ test_files:
|
|
148
149
|
- spec/private/recognize_spec.rb
|
149
150
|
- spec/private/request_method_spec.rb
|
150
151
|
- spec/private/splitter_spec.rb
|
151
|
-
- spec/private/string_scanner_spec.rb
|
152
152
|
- spec/private/url_parts_spec.rb
|
153
153
|
- spec/spec_helper.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
#TODO: rewrite this in C and commit this addition back to community
|
4
|
-
class StringScanner
|
5
|
-
# scan_before(pattern)
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# Scans the string until the +pattern+ is matched. As opposed to #scan_until,
|
9
|
-
# it does not include a matching pattern into a returning value and sets
|
10
|
-
# pointer just _before_ the pattern position.
|
11
|
-
# If there is no match, +nil+ is returned.
|
12
|
-
#
|
13
|
-
# s = StringScanner.new("Fri Dec 12 1975 14:39")
|
14
|
-
# s.scan_until(/1/) # -> "Fri Dec "
|
15
|
-
# s.scan(/1/) # -> "1"
|
16
|
-
# s.scan_until(/1/) # -> nil
|
17
|
-
#
|
18
|
-
def scan_before(pattern)
|
19
|
-
return nil unless self.exist?(pattern)
|
20
|
-
|
21
|
-
pattern_size = self.matched_size
|
22
|
-
result = self.scan_until(pattern)
|
23
|
-
|
24
|
-
self.pos = self.pos - pattern_size
|
25
|
-
(result.length == pattern_size) ?
|
26
|
-
(result = '') :
|
27
|
-
(result = result[0..(result.length - pattern_size - 1)])
|
28
|
-
|
29
|
-
result
|
30
|
-
end
|
31
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
-
require "usher"
|
3
|
-
|
4
|
-
describe StringScanner do
|
5
|
-
describe "#scan_before" do
|
6
|
-
before :each do
|
7
|
-
@scanner = StringScanner.new("/one/two..three")
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "when there is a match" do
|
11
|
-
it "should return subsequent string without matching pattern in the end" do
|
12
|
-
@scanner.scan_before(/\.\./).should == "/one/two"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set pointer right before the matching pattern" do
|
16
|
-
@scanner.scan_before(/\.\./)
|
17
|
-
@scanner.scan(/\.\./).should == '..'
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "when matching pattern is right at the position" do
|
21
|
-
it "should return empty string" do
|
22
|
-
@scanner.scan_before(/\//).should == ''
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "when there is no match" do
|
28
|
-
it "should return nil" do
|
29
|
-
@scanner.scan_before(/bla-bla-bla/).should == nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should not move the pointer" do
|
33
|
-
@scanner.scan_before(/bla-bla-bla/)
|
34
|
-
@scanner.pos.should == 0
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|