usher 0.6.1 → 0.6.2
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 +32 -8
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/usher/interface/rack.rb
CHANGED
@@ -4,6 +4,24 @@ require File.join(File.dirname(__FILE__), 'rack', 'route')
|
|
4
4
|
class Usher
|
5
5
|
module Interface
|
6
6
|
class Rack
|
7
|
+
|
8
|
+
ENV_KEY_RESPONSE = 'usher.response'
|
9
|
+
ENV_KEY_PARAMS = 'usher.params'
|
10
|
+
|
11
|
+
class Middleware
|
12
|
+
|
13
|
+
def initialize(app, router)
|
14
|
+
@app = app
|
15
|
+
@router = router
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@router.call(env)
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
7
25
|
class Builder < ::Rack::Builder
|
8
26
|
def initialize(&block)
|
9
27
|
@usher = Usher::Interface::Rack.new
|
@@ -37,12 +55,17 @@ class Usher
|
|
37
55
|
|
38
56
|
attr_reader :router
|
39
57
|
|
40
|
-
def initialize(app = nil, &blk)
|
58
|
+
def initialize(app = nil, options = nil, &blk)
|
41
59
|
@_app = app || lambda { |env| ::Rack::Response.new("No route found", 404).finish }
|
42
60
|
@router = Usher.new(:request_methods => [:request_method, :host, :port, :scheme], :generator => Usher::Util::Generators::URL.new)
|
61
|
+
@use_destinations = options && options.key?(:use_destinations) ? options[:use_destinations] : true
|
43
62
|
instance_eval(&blk) if blk
|
44
63
|
end
|
45
64
|
|
65
|
+
def use_destinations?
|
66
|
+
@use_destinations
|
67
|
+
end
|
68
|
+
|
46
69
|
def dup
|
47
70
|
new_one = super
|
48
71
|
original = self
|
@@ -114,13 +137,14 @@ class Usher
|
|
114
137
|
#
|
115
138
|
# @api plugin
|
116
139
|
def after_match(request, response)
|
117
|
-
params = response.path.route.default_values ?
|
118
|
-
response.path.route.default_values.merge(Hash[*response.params.flatten]) :
|
119
|
-
Hash[*response.params.flatten]
|
140
|
+
params = response.path.route.default_values ? response.path.route.default_values.merge(response.params_as_hash) : response.params_as_hash
|
120
141
|
|
121
|
-
request.env[
|
122
|
-
|
123
|
-
|
142
|
+
request.env[ENV_KEY_RESPONSE] ||= []
|
143
|
+
request.env[ENV_KEY_RESPONSE] << response
|
144
|
+
|
145
|
+
request.env[ENV_KEY_PARAMS] ?
|
146
|
+
request.env[ENV_KEY_PARAMS].merge!(params) :
|
147
|
+
(request.env[ENV_KEY_PARAMS] = params)
|
124
148
|
|
125
149
|
# consume the path_info to the script_name
|
126
150
|
# response.remaining_path
|
@@ -135,7 +159,7 @@ class Usher
|
|
135
159
|
#
|
136
160
|
# @api private
|
137
161
|
def determine_respondant(response)
|
138
|
-
response && response.destination || _app
|
162
|
+
use_destinations? && response && response.destination || _app
|
139
163
|
end
|
140
164
|
|
141
165
|
# Consume the path from path_info to script_name
|
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.2
|
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: 2010-01-
|
17
|
+
date: 2010-01-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|