usher 0.6.0 → 0.6.1
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/VERSION.yml +1 -1
- data/lib/usher/interface/rack.rb +13 -11
- data/lib/usher/interface/sinatra.rb +1 -1
- data/lib/usher/route.rb +8 -0
- data/lib/usher.rb +9 -0
- data/spec/private/rack/dispatch_spec.rb +3 -3
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/usher/interface/rack.rb
CHANGED
@@ -36,10 +36,9 @@ class Usher
|
|
36
36
|
end
|
37
37
|
|
38
38
|
attr_reader :router
|
39
|
-
attr_accessor :app
|
40
39
|
|
41
40
|
def initialize(app = nil, &blk)
|
42
|
-
@
|
41
|
+
@_app = app || lambda { |env| ::Rack::Response.new("No route found", 404).finish }
|
43
42
|
@router = Usher.new(:request_methods => [:request_method, :host, :port, :scheme], :generator => Usher::Util::Generators::URL.new)
|
44
43
|
instance_eval(&blk) if blk
|
45
44
|
end
|
@@ -56,11 +55,12 @@ class Usher
|
|
56
55
|
def add(path, options = nil)
|
57
56
|
@router.add_route(path, options)
|
58
57
|
end
|
59
|
-
|
58
|
+
alias_method :path, :add
|
59
|
+
|
60
60
|
# default { |env| ... }
|
61
61
|
# default DefaultApp
|
62
62
|
def default(app = nil, &block)
|
63
|
-
@
|
63
|
+
@_app = app ? app : block
|
64
64
|
end
|
65
65
|
|
66
66
|
# shortcuts for adding routes for HTTP methods, for example:
|
@@ -135,13 +135,7 @@ class Usher
|
|
135
135
|
#
|
136
136
|
# @api private
|
137
137
|
def determine_respondant(response)
|
138
|
-
|
139
|
-
app
|
140
|
-
else
|
141
|
-
respondant = response.path.route.destination
|
142
|
-
respondant = app unless respondant.respond_to?(:call)
|
143
|
-
respondant
|
144
|
-
end
|
138
|
+
response && response.destination || _app
|
145
139
|
end
|
146
140
|
|
147
141
|
# Consume the path from path_info to script_name
|
@@ -149,6 +143,14 @@ class Usher
|
|
149
143
|
request.env["SCRIPT_NAME"] = (request.env["SCRIPT_NAME"] + response.matched_path) || ""
|
150
144
|
request.env["PATH_INFO"] = response.remaining_path || ""
|
151
145
|
end
|
146
|
+
|
147
|
+
def default_app
|
148
|
+
_app
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
attr_reader :_app
|
153
|
+
|
152
154
|
end
|
153
155
|
end
|
154
156
|
end
|
@@ -38,7 +38,7 @@ class Usher
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def route!(base = self.class)
|
41
|
-
if self.class.router and match = self.class.router.recognize(@request)
|
41
|
+
if self.class.router and match = self.class.router.recognize(@request, @request.path_info)
|
42
42
|
@block_params = match.params.map{|p| p.last}
|
43
43
|
@params = @params ? @params.merge(match.params_as_hash) : match.params_as_hash
|
44
44
|
route_eval(&match.destination)
|
data/lib/usher/route.rb
CHANGED
@@ -33,6 +33,14 @@ class Usher
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def inspect
|
37
|
+
"#<Usher:Route:0x%x @paths=[%s]>" % [self.object_id, paths.collect{|p| p.parts.join}.join(', ')]
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
inspect
|
42
|
+
end
|
43
|
+
|
36
44
|
def grapher
|
37
45
|
unless @grapher
|
38
46
|
@grapher = Grapher.new(router)
|
data/lib/usher.rb
CHANGED
@@ -272,6 +272,14 @@ class Usher
|
|
272
272
|
replacement
|
273
273
|
end
|
274
274
|
|
275
|
+
def inspect
|
276
|
+
"#<Usher:0x%x route_count=%d delimiters=%s request_methods=%s ignore_trailing_delimiters? %s consider_destination_keys? %s can_generate? %s priority_lookups? %s>" % [self.object_id, route_count, self.delimiters.inspect, request_methods.inspect, ignore_trailing_delimiters.inspect, consider_destination_keys.inspect, can_generate?.inspect, priority_lookups.inspect]
|
277
|
+
end
|
278
|
+
|
279
|
+
def to_s
|
280
|
+
inspect
|
281
|
+
end
|
282
|
+
|
275
283
|
private
|
276
284
|
|
277
285
|
attr_accessor :request_methods, :ignore_trailing_delimiters, :consider_destination_keys
|
@@ -333,4 +341,5 @@ class Usher
|
|
333
341
|
@grapher = Grapher.new(self)
|
334
342
|
@routes.each{|r| @grapher.add_route(r)}
|
335
343
|
end
|
344
|
+
|
336
345
|
end
|
@@ -238,7 +238,7 @@ describe "Usher (for rack) route dispatching" do
|
|
238
238
|
@app.should_receive(:call).with{|e| e['usher.params'].should == {:middle => :ware}}
|
239
239
|
|
240
240
|
u = Usher::Interface.for(:rack)
|
241
|
-
u.
|
241
|
+
u.default @app
|
242
242
|
u.add("/foo", :default_values => {:middle => :ware}).name(:foo)
|
243
243
|
|
244
244
|
u.call(Rack::MockRequest.env_for("/foo"))
|
@@ -248,14 +248,14 @@ describe "Usher (for rack) route dispatching" do
|
|
248
248
|
env = Rack::MockRequest.env_for("/not_a_route")
|
249
249
|
@app.should_receive(:call).with(env)
|
250
250
|
u = Usher::Interface.for(:rack)
|
251
|
-
u.
|
251
|
+
u.default @app
|
252
252
|
u.call(env)
|
253
253
|
end
|
254
254
|
|
255
255
|
it "should allow me to set the application after initialization" do
|
256
256
|
@app.should_receive(:call).with{|e| e['usher.params'].should == {:after => :stuff}}
|
257
257
|
u = Usher::Interface.for(:rack)
|
258
|
-
u.
|
258
|
+
u.default @app
|
259
259
|
u.add("/foo", :default_values => {:after => :stuff})
|
260
260
|
u.call(Rack::MockRequest.env_for("/foo"))
|
261
261
|
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.6.
|
4
|
+
version: 0.6.1
|
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:
|
17
|
+
date: 2010-01-04 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|