usher 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +9 -0
- data/VERSION.yml +1 -1
- data/lib/usher/node/response.rb +2 -2
- data/lib/usher/node/root.rb +4 -0
- data/lib/usher/node.rb +71 -48
- data/lib/usher/route/path.rb +1 -1
- data/lib/usher/util/generate.rb +2 -2
- data/lib/usher/util/parser.rb +3 -3
- data/lib/usher.rb +5 -1
- metadata +3 -2
data/CHANGES.rdoc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= Changelog
|
2
|
+
|
3
|
+
== From 0.6.5 to 0.6.6
|
4
|
+
|
5
|
+
* Faster recognition (~10%)
|
6
|
+
* Nicer exception message when generating a route and raising a MissingParameterException
|
7
|
+
* Nodes now support #ancestors and #root methods.
|
8
|
+
* Cache responses on non-dynamic paths.
|
9
|
+
* Started a changelog.
|
data/VERSION.yml
CHANGED
data/lib/usher/node/response.rb
CHANGED
@@ -3,7 +3,7 @@ class Usher
|
|
3
3
|
class Response < Struct.new(:path, :params_as_array, :remaining_path, :matched_path)
|
4
4
|
|
5
5
|
def params
|
6
|
-
@params ||=
|
6
|
+
@params ||= path.convert_params_array(params_as_array)
|
7
7
|
end
|
8
8
|
|
9
9
|
def partial_match?
|
@@ -11,7 +11,7 @@ class Usher
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def params_as_hash
|
14
|
-
@params_as_hash ||= params_as_array.
|
14
|
+
@params_as_hash ||= params_as_array.inject({}){|hash, val| hash[path.dynamic_keys[hash.size]] = val; hash}
|
15
15
|
end
|
16
16
|
|
17
17
|
def destination
|
data/lib/usher/node/root.rb
CHANGED
data/lib/usher/node.rb
CHANGED
@@ -52,6 +52,26 @@ class Usher
|
|
52
52
|
@terminates && @terminates.route.recognizable?
|
53
53
|
end
|
54
54
|
|
55
|
+
def ancestors
|
56
|
+
unless @ancestors
|
57
|
+
@ancestors = []
|
58
|
+
node = self
|
59
|
+
while (node.respond_to?(:parent))
|
60
|
+
@ancestors << node
|
61
|
+
node = node.parent
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@ancestors
|
65
|
+
end
|
66
|
+
|
67
|
+
def root
|
68
|
+
@root ||= ancestors.last
|
69
|
+
end
|
70
|
+
|
71
|
+
def route_set
|
72
|
+
@route_set ||= root.route_set
|
73
|
+
end
|
74
|
+
|
55
75
|
def pp
|
56
76
|
$stdout << " " * depth
|
57
77
|
$stdout << "#{terminates? ? '* ' : ''}#{depth}: #{value.inspect}\n"
|
@@ -72,68 +92,71 @@ class Usher
|
|
72
92
|
end if request
|
73
93
|
end
|
74
94
|
|
75
|
-
def find(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
95
|
+
def find(request_object, original_path, path, params = [])
|
96
|
+
# terminates or is partial
|
97
|
+
if terminates? && (path.empty? || terminates.route.partial_match? || (route_set.ignore_trailing_delimiters? && path.all?{|p| route_set.delimiters.include?(p)}))
|
98
|
+
if terminates.cached_response
|
99
|
+
terminates.cached_response
|
100
|
+
else
|
101
|
+
terminates.route.partial_match? ?
|
102
|
+
Response.new(terminates, params, path.join, original_path[0, original_path.size - path.join.size]) :
|
103
|
+
Response.new(terminates, params, nil, original_path)
|
104
|
+
end
|
105
|
+
# terminates or is partial
|
106
|
+
elsif !path.empty? and greedy and match_with_result_output = greedy.match_with_result(whole_path = path.join)
|
81
107
|
next_path, matched_part = match_with_result_output
|
82
|
-
position += matched_part.size
|
83
108
|
whole_path.slice!(0, matched_part.size)
|
84
|
-
|
85
|
-
next_path.find(
|
109
|
+
params << matched_part if next_path.value.is_a?(Route::Variable)
|
110
|
+
next_path.find(request_object, original_path, whole_path.empty? ? whole_path : route_set.splitter.split(whole_path), params)
|
86
111
|
elsif !path.empty? and normal and next_part = normal[path.first] || normal[nil]
|
87
112
|
part = path.shift
|
88
|
-
position += part.size
|
89
113
|
case next_part.value
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
until path.empty? || (
|
114
|
+
when String
|
115
|
+
when Route::Variable::Single
|
116
|
+
# get the variable
|
117
|
+
variable = next_part.value
|
118
|
+
# do a validity check
|
119
|
+
variable.valid!(part)
|
120
|
+
# because its a variable, we need to add it to the params array
|
121
|
+
parameter_value = part
|
122
|
+
if variable.look_ahead
|
123
|
+
until path.empty? || (variable.look_ahead === path.first) # variables have a look ahead notion,
|
100
124
|
next_path_part = path.shift # and until they are satified,
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
position -= next_part.parent.value.size
|
113
|
-
end
|
114
|
-
break
|
115
|
-
elsif !usher.delimiters.unescaped.include?(part)
|
116
|
-
next_part.value.valid!(part)
|
117
|
-
params.last << part
|
118
|
-
end
|
119
|
-
if path.empty?
|
120
|
-
break
|
121
|
-
else
|
122
|
-
part = path.shift
|
125
|
+
parameter_value << next_path_part
|
126
|
+
end
|
127
|
+
end
|
128
|
+
params << parameter_value
|
129
|
+
when Route::Variable::Glob
|
130
|
+
params << []
|
131
|
+
loop do
|
132
|
+
if (next_part.value.look_ahead === part || (!route_set.delimiters.unescaped.include?(part) && next_part.value.regex_matcher && !next_part.value.regex_matcher.match(part)))
|
133
|
+
path.unshift(part)
|
134
|
+
if route_set.delimiters.unescaped.include?(next_part.parent.value)
|
135
|
+
path.unshift(next_part.parent.value)
|
123
136
|
end
|
137
|
+
break
|
138
|
+
elsif !route_set.delimiters.unescaped.include?(part)
|
139
|
+
next_part.value.valid!(part)
|
140
|
+
params.last << part
|
141
|
+
end
|
142
|
+
if path.empty?
|
143
|
+
break
|
144
|
+
else
|
145
|
+
part = path.shift
|
124
146
|
end
|
147
|
+
end
|
125
148
|
end
|
126
|
-
next_part.find(
|
149
|
+
next_part.find(request_object, original_path, path, params)
|
127
150
|
elsif request_method_type
|
128
|
-
return_value = if (specific_node = request[request_object.send(request_method_type)] and ret = specific_node.find(
|
129
|
-
|
151
|
+
return_value = if (specific_node = request[request_object.send(request_method_type)] and ret = specific_node.find(request_object, original_path, path.dup, params && params.dup))
|
152
|
+
route_set.priority_lookups? ? [ret] : ret
|
130
153
|
end
|
131
154
|
|
132
|
-
if
|
133
|
-
return_value =
|
155
|
+
if route_set.priority_lookups? || return_value.nil? and general_node = request[nil] and ret = general_node.find(request_object, original_path, path.dup, params && params.dup)
|
156
|
+
return_value = route_set.priority_lookups? && return_value ? [return_value, ret] : ret
|
134
157
|
end
|
135
158
|
|
136
|
-
unless
|
159
|
+
unless route_set.priority_lookups?
|
137
160
|
return_value
|
138
161
|
else
|
139
162
|
return_value = Array(return_value).flatten.compact
|
data/lib/usher/route/path.rb
CHANGED
data/lib/usher/util/generate.rb
CHANGED
@@ -21,14 +21,14 @@ class Usher
|
|
21
21
|
when String
|
22
22
|
result << part
|
23
23
|
when Route::Variable::Glob
|
24
|
-
value = (params && params.delete(part.name)) || part.default_value || raise(MissingParameterException.new)
|
24
|
+
value = (params && params.delete(part.name)) || part.default_value || raise(MissingParameterException.new("expected a value for #{part.name}"))
|
25
25
|
value.each_with_index do |current_value, index|
|
26
26
|
part.valid!(current_value)
|
27
27
|
result << current_value.to_s
|
28
28
|
result << usher.delimiters.first if index != value.size - 1
|
29
29
|
end
|
30
30
|
when Route::Variable
|
31
|
-
value = (params && params.delete(part.name)) || part.default_value || raise(MissingParameterException.new)
|
31
|
+
value = (params && params.delete(part.name)) || part.default_value || raise(MissingParameterException.new("expected a value for #{part.name}"))
|
32
32
|
part.valid!(value)
|
33
33
|
result << value.to_s
|
34
34
|
end
|
data/lib/usher/util/parser.rb
CHANGED
@@ -123,9 +123,9 @@ class Usher
|
|
123
123
|
if variable
|
124
124
|
variable_type = variable.slice!(0).chr.to_sym
|
125
125
|
variable_class = case variable_type
|
126
|
-
when :'!'
|
127
|
-
when :*
|
128
|
-
when :':'
|
126
|
+
when :'!' then Usher::Route::Variable::Greedy
|
127
|
+
when :* then Usher::Route::Variable::Glob
|
128
|
+
when :':' then Usher::Route::Variable::Single
|
129
129
|
end
|
130
130
|
variable_name = variable[0, variable.size - 1].to_sym
|
131
131
|
current_group << variable_class.new(variable_name, regex, requirements && requirements[variable_name])
|
data/lib/usher.rb
CHANGED
@@ -232,7 +232,11 @@ class Usher
|
|
232
232
|
# route = set.add_route('/test')
|
233
233
|
# set.recognize(Request.new('/test')).path.route == route => true
|
234
234
|
def recognize(request, path = request.path)
|
235
|
-
@root.find(
|
235
|
+
response = @root.find(request, path, @splitter.split(path))
|
236
|
+
if response && !response.path.dynamic?
|
237
|
+
response.path.cached_response = response
|
238
|
+
end
|
239
|
+
response
|
236
240
|
end
|
237
241
|
|
238
242
|
# Recognizes a +path+ and returns +nil+ or an Usher::Node::Response, which is a struct containing a Usher::Route::Path and an array of arrays containing the extracted parameters. Convenience method for when recognizing on the request object is unneeded.
|
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.6
|
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-15 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -36,6 +36,7 @@ extensions: []
|
|
36
36
|
extra_rdoc_files:
|
37
37
|
- README.rdoc
|
38
38
|
files:
|
39
|
+
- CHANGES.rdoc
|
39
40
|
- History.txt
|
40
41
|
- Manifest.txt
|
41
42
|
- README.rdoc
|