hobbit-contrib 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/hobbit/contrib/version.rb +1 -1
- data/lib/hobbit/filter.rb +11 -17
- data/test/filter_test.rb +24 -27
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 185258fc6ea56da609487b2888247abdd6cde2cb
|
4
|
+
data.tar.gz: 23dffe0b7043f1ebd7fe4683100cd50a119e30dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc8f6211e9c33a16d806060ed02cb03d03ea68403087d8db43701abaef761583db7404150bbe4d0251ae8c9a8a2684268672fb1c20ef5d33981502215ab50e7
|
7
|
+
data.tar.gz: b75286914679c427040fe57f20b51db83ab76c998764ebfd9641af6e5f04897ca18bd39d6066932e71c46620aaa0d2452c67bdf0046225ec2519f7d2f2fed694
|
data/CHANGELOG.md
CHANGED
data/lib/hobbit/filter.rb
CHANGED
@@ -54,26 +54,20 @@ module Hobbit
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def filter(kind)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def find_filter(kind)
|
65
|
-
filter = self.class.filters[kind].detect do |f|
|
66
|
-
f[:compiled_path] =~ request.path_info || f[:compiled_path] =~ ''
|
67
|
-
end
|
68
|
-
|
69
|
-
if filter
|
70
|
-
$~.captures.each_with_index do |value, index|
|
71
|
-
param = filter[:extra_params][index]
|
72
|
-
request.params[param] = value
|
57
|
+
find_filters(kind).each do |filter|
|
58
|
+
if filter[:compiled_path] =~ request.path_info
|
59
|
+
$~.captures.each_with_index do |value, index|
|
60
|
+
param = filter[:extra_params][index]
|
61
|
+
request.params[param] = value
|
62
|
+
end
|
73
63
|
end
|
64
|
+
instance_eval &filter[:block]
|
74
65
|
end
|
66
|
+
response.finish if kind == :after
|
67
|
+
end
|
75
68
|
|
76
|
-
|
69
|
+
def find_filters(kind)
|
70
|
+
self.class.filters[kind].select { |f| f[:compiled_path] =~ request.path_info || f[:compiled_path] =~ '' }
|
77
71
|
end
|
78
72
|
end
|
79
73
|
end
|
data/test/filter_test.rb
CHANGED
@@ -21,31 +21,28 @@ scope Hobbit::Filter do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
%w(after before).each do |kind|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
scope "::#{kind}" do
|
25
|
+
test do
|
26
|
+
p = Proc.new { 'do something' }
|
27
|
+
app = mock_app do
|
28
|
+
include Hobbit::Filter
|
29
|
+
send kind, &p
|
30
|
+
end
|
31
|
+
|
32
|
+
assert app.to_app.class.filters[:"#{kind}"].size == 1
|
33
|
+
assert app.to_app.class.filters[:"#{kind}"].first[:block].call == p.call
|
31
34
|
end
|
32
|
-
|
33
|
-
assert app.to_app.class.filters[:#{kind}].size == 1
|
34
|
-
assert app.to_app.class.filters[:#{kind}].first[:block].call == p.call
|
35
35
|
end
|
36
|
-
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
scope 'when a filter matches' do
|
38
|
+
test "calls the filters' block" do
|
39
|
+
get '/'
|
40
|
+
assert last_response.ok?
|
41
|
+
assert last_request.env.include? "hobbit.#{kind}"
|
42
|
+
assert last_request.env["hobbit.#{kind}"] == "this is #{kind}"
|
43
|
+
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
EOS
|
47
|
-
instance_eval str
|
48
|
-
end
|
49
46
|
|
50
47
|
scope '::filters' do
|
51
48
|
test 'returns a Hash' do
|
@@ -142,32 +139,32 @@ EOS
|
|
142
139
|
include Hobbit::Filter
|
143
140
|
|
144
141
|
before do
|
145
|
-
env['hobbit.before'] = 'this will match'
|
142
|
+
env['hobbit.before'] = ['this will match']
|
146
143
|
end
|
147
144
|
|
148
145
|
before '/' do
|
149
|
-
env['hobbit.before']
|
146
|
+
env['hobbit.before'] << 'this will match too'
|
150
147
|
end
|
151
148
|
|
152
149
|
after do
|
153
|
-
env['hobbit.after'] = 'this will match'
|
150
|
+
env['hobbit.after'] = ['this will match']
|
154
151
|
end
|
155
152
|
|
156
153
|
after '/' do
|
157
|
-
env['hobbit.after']
|
154
|
+
env['hobbit.after'] << 'this will match too'
|
158
155
|
end
|
159
156
|
|
160
157
|
get('/') { 'GET /' }
|
161
158
|
end
|
162
159
|
end
|
163
160
|
|
164
|
-
test 'calls
|
161
|
+
test 'calls all matching filters' do
|
165
162
|
get '/'
|
166
163
|
assert last_response.ok?
|
167
164
|
assert last_request.env.include? 'hobbit.before'
|
168
|
-
|
165
|
+
assert_equal ['this will match', 'this will match too'], last_request.env['hobbit.before']
|
169
166
|
assert last_request.env.include? 'hobbit.after'
|
170
|
-
|
167
|
+
assert_equal ['this will match', 'this will match too'], last_request.env['hobbit.after']
|
171
168
|
end
|
172
169
|
end
|
173
170
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobbit-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|