roda 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/doc/release_notes/2.6.0.txt +21 -0
- data/lib/roda/plugins/caching.rb +2 -2
- data/lib/roda/plugins/csrf.rb +10 -1
- data/lib/roda/plugins/hooks.rb +7 -5
- data/lib/roda/plugins/param_matchers.rb +34 -4
- data/lib/roda/plugins/render.rb +2 -2
- data/lib/roda/version.rb +2 -2
- data/spec/plugin/csrf_spec.rb +3 -0
- data/spec/plugin/hooks_spec.rb +8 -0
- data/spec/plugin/param_matchers_spec.rb +39 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b5d148505b95423a029a85acb7ab453ad50518
|
4
|
+
data.tar.gz: 825e0915b23389bb468b335fcadd2c102362f6ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c7ba330521161433166bd7ca685619366459800a28fa06b4a2328232cfced10a796ddd67aa16927a1be44ee3b31c1c8848847b987dd87d506ae501e3acf78c
|
7
|
+
data.tar.gz: c35370d775528f676f4ad1be2c9cc277f4d0d1082a7750a62418c28ebadc85b6e01056ad4699ea866e55941a8747323f8d3c666faa2b58c265027343685f6ae8
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 2.6.0 (2015-09-14)
|
2
|
+
|
3
|
+
* Add :params and :params! matchers to param_matchers plugin (jeremyevans)
|
4
|
+
|
5
|
+
* Merge options when loading csrf plugin multiple times (jeremyevans)
|
6
|
+
|
7
|
+
* Allow request.halt to work in before hooks in the hooks plugin (celsworth) (#38)
|
8
|
+
|
1
9
|
= 2.5.1 (2015-08-13)
|
2
10
|
|
3
11
|
* Allow multi_route and middleware plugins to work together (janko-m) (#36)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* :params and :params! matchers have been added to the param_matchers
|
4
|
+
plugin, allowing you to match multiple params at the same time:
|
5
|
+
|
6
|
+
r.on :params=>%w'foo bar' do |foo, bar| end
|
7
|
+
# instead of
|
8
|
+
r.on({:param=>'foo'}, :param=>'bar') do |foo, bar| end
|
9
|
+
|
10
|
+
= Other Improvements
|
11
|
+
|
12
|
+
* When loading the csrf plugin multiple times, instead of loading the
|
13
|
+
middleware multiple times with different settings, merge options
|
14
|
+
in later plugin calls into a single middleware option hash, and
|
15
|
+
only load the middleware once.
|
16
|
+
|
17
|
+
This allows plugins to depend on the csrf plugin, while also
|
18
|
+
allowing the application to use the csrf plugin with options.
|
19
|
+
|
20
|
+
* request.halt now works correctly when used inside a before hook when
|
21
|
+
using the hooks plugin.
|
data/lib/roda/plugins/caching.rb
CHANGED
@@ -5,7 +5,7 @@ class Roda
|
|
5
5
|
# For proper caching, you should use either the +last_modified+ or
|
6
6
|
# +etag+ request methods.
|
7
7
|
#
|
8
|
-
# r.get '
|
8
|
+
# r.get 'albums/:d' do |album_id|
|
9
9
|
# @album = Album[album_id]
|
10
10
|
# r.last_modified @album.updated_at
|
11
11
|
# view('album')
|
@@ -13,7 +13,7 @@ class Roda
|
|
13
13
|
#
|
14
14
|
# # or
|
15
15
|
#
|
16
|
-
# r.get '
|
16
|
+
# r.get 'albums/:d' do |album_id|
|
17
17
|
# @album = Album[album_id]
|
18
18
|
# r.etag @album.sha1
|
19
19
|
# view('album')
|
data/lib/roda/plugins/csrf.rb
CHANGED
@@ -24,7 +24,16 @@ class Roda
|
|
24
24
|
|
25
25
|
# Load the Rack::Csrf middleware into the app with the given options.
|
26
26
|
def self.configure(app, opts={})
|
27
|
-
app.
|
27
|
+
app.instance_exec do
|
28
|
+
@middleware.each do |(mid, *rest), _|
|
29
|
+
if mid.equal?(CSRF)
|
30
|
+
rest[0].merge!(opts)
|
31
|
+
build_rack_app
|
32
|
+
return
|
33
|
+
end
|
34
|
+
end
|
35
|
+
use CSRF, opts
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
module InstanceMethods
|
data/lib/roda/plugins/hooks.rb
CHANGED
@@ -69,12 +69,14 @@ class Roda
|
|
69
69
|
module InstanceMethods
|
70
70
|
# Before routing, execute the before hooks, and
|
71
71
|
# execute the after hooks before returning.
|
72
|
-
def call
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
def call(&block)
|
73
|
+
res = super do |r|
|
74
|
+
if b = opts[:before_hook]
|
75
|
+
instance_exec(&b)
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
+
instance_exec(r, &block)
|
79
|
+
end
|
78
80
|
ensure
|
79
81
|
if b = opts[:after_hook]
|
80
82
|
instance_exec(res, &b)
|
@@ -4,7 +4,7 @@ class Roda
|
|
4
4
|
# on the request's params.
|
5
5
|
#
|
6
6
|
# It adds a :param matcher for matching on any param with the
|
7
|
-
# same name, yielding the value of the param
|
7
|
+
# same name, yielding the value of the param:
|
8
8
|
#
|
9
9
|
# r.on :param => 'foo' do |value|
|
10
10
|
# # Matches '?foo=bar', '?foo='
|
@@ -12,16 +12,30 @@ class Roda
|
|
12
12
|
# end
|
13
13
|
#
|
14
14
|
# It adds a :param! matcher for matching on any non-empty param
|
15
|
-
# with the same name, yielding the value of the param
|
15
|
+
# with the same name, yielding the value of the param:
|
16
16
|
#
|
17
17
|
# r.on(:param! => 'foo') do |value|
|
18
18
|
# # Matches '?foo=bar'
|
19
19
|
# # Doesn't match '?foo=', '?bar=foo'
|
20
20
|
# end
|
21
|
+
#
|
22
|
+
# It also adds :params and :params! matchers, for matching multiple
|
23
|
+
# params at the same time:
|
24
|
+
#
|
25
|
+
# r.on :params => ['foo', 'baz'] do |value|
|
26
|
+
# # Matches '?foo=bar&baz=quuz', '?foo=&baz='
|
27
|
+
# # Doesn't match '?foo=bar', '?baz='
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# r.on :params! => ['foo', 'baz'] do |value|
|
31
|
+
# # Matches '?foo=bar&baz=quuz'
|
32
|
+
# # Doesn't match '?foo=bar', '?baz=', '?foo=&baz=', '?foo=bar&baz='
|
33
|
+
# end
|
34
|
+
#
|
21
35
|
module ParamMatchers
|
22
36
|
module RequestMethods
|
23
37
|
# Match the given parameter if present, even if the parameter is empty.
|
24
|
-
# Adds
|
38
|
+
# Adds match to the captures.
|
25
39
|
def match_param(key)
|
26
40
|
if v = self[key]
|
27
41
|
@captures << v
|
@@ -29,12 +43,28 @@ class Roda
|
|
29
43
|
end
|
30
44
|
|
31
45
|
# Match the given parameter if present and not empty.
|
32
|
-
# Adds
|
46
|
+
# Adds match to the captures.
|
33
47
|
def match_param!(key)
|
34
48
|
if (v = self[key]) && !v.empty?
|
35
49
|
@captures << v
|
36
50
|
end
|
37
51
|
end
|
52
|
+
|
53
|
+
# Match all given parameters if present, even if any/all parameters is empty.
|
54
|
+
# Adds all matches to the captures.
|
55
|
+
def match_params(keys)
|
56
|
+
keys.each do |key|
|
57
|
+
return false unless match_param(key)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Match all given parameters if present and not empty.
|
62
|
+
# Adds all matches to the captures.
|
63
|
+
def match_params!(keys)
|
64
|
+
keys.each do |key|
|
65
|
+
return false unless match_param!(key)
|
66
|
+
end
|
67
|
+
end
|
38
68
|
end
|
39
69
|
end
|
40
70
|
|
data/lib/roda/plugins/render.rb
CHANGED
@@ -36,7 +36,7 @@ class Roda
|
|
36
36
|
# <tt><%== %></tt> not escape output, and handles postfix conditions inside
|
37
37
|
# <tt><%= %></tt> tags.
|
38
38
|
# :escape_safe_classes :: String subclasses that should not be HTML escaped when used in
|
39
|
-
#
|
39
|
+
# <tt><%= %></tt> tags, when :escape is used. Can be an array for multiple classes.
|
40
40
|
# :escaper :: Object used for escaping output of <tt><%= %></tt>, when :escape is used,
|
41
41
|
# overriding the default. If given, object should respond to +escape_xml+ with
|
42
42
|
# a single argument and return an output string.
|
@@ -44,7 +44,7 @@ class Roda
|
|
44
44
|
# :layout_opts :: The options to use when rendering the layout, if different
|
45
45
|
# from the default options.
|
46
46
|
# :template_opts :: The tilt options used when rendering all templates. defaults to:
|
47
|
-
#
|
47
|
+
# <tt>{:outvar=>'@_out_buf', :default_encoding=>Encoding.default_external}</tt>.
|
48
48
|
# :engine_opts :: The tilt options to use per template engine. Keys are
|
49
49
|
# engine strings, values are hashes of template options.
|
50
50
|
# :views :: The directory holding the view files, defaults to the 'views' subdirectory of the
|
data/lib/roda/version.rb
CHANGED
@@ -4,11 +4,11 @@ class Roda
|
|
4
4
|
RodaMajorVersion = 2
|
5
5
|
|
6
6
|
# The minor version of Roda, updated for new feature releases of Roda.
|
7
|
-
RodaMinorVersion =
|
7
|
+
RodaMinorVersion = 6
|
8
8
|
|
9
9
|
# The patch version of Roda, updated only for bug fixes from the last
|
10
10
|
# feature release.
|
11
|
-
RodaPatchVersion =
|
11
|
+
RodaPatchVersion = 0
|
12
12
|
|
13
13
|
# The full version of Roda as a string.
|
14
14
|
RodaVersion = "#{RodaMajorVersion}.#{RodaMinorVersion}.#{RodaPatchVersion}".freeze
|
data/spec/plugin/csrf_spec.rb
CHANGED
@@ -44,6 +44,9 @@ describe "csrf plugin" do
|
|
44
44
|
s, _, b = req('/', env[h].merge('REQUEST_METHOD'=>'POST', 'rack.input'=>io, "HTTP_#{h['HEADER']}"=>h['TOKEN']))
|
45
45
|
s.must_equal 200
|
46
46
|
b.must_equal ['p']
|
47
|
+
|
48
|
+
app.plugin :csrf
|
49
|
+
body('/foo', 'REQUEST_METHOD'=>'POST', 'rack.input'=>io).must_equal 'bar'
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
data/spec/plugin/hooks_spec.rb
CHANGED
@@ -92,4 +92,12 @@ describe "hooks plugin" do
|
|
92
92
|
b.join.must_equal 'foo'
|
93
93
|
@a.must_equal [[200, 'bar', ['foo']]]
|
94
94
|
end
|
95
|
+
|
96
|
+
it "handles halt in before blocks" do
|
97
|
+
app.before do
|
98
|
+
response.status = 200
|
99
|
+
request.halt
|
100
|
+
end
|
101
|
+
status.must_equal 201
|
102
|
+
end
|
95
103
|
end
|
@@ -7,9 +7,7 @@ describe "param_matchers plugin" do
|
|
7
7
|
email
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
"No email"
|
12
|
-
end
|
10
|
+
"No email"
|
13
11
|
end
|
14
12
|
|
15
13
|
io = StringIO.new
|
@@ -18,15 +16,13 @@ describe "param_matchers plugin" do
|
|
18
16
|
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal 'No email'
|
19
17
|
end
|
20
18
|
|
21
|
-
it "param
|
19
|
+
it "param matcher should yield a param only if given" do
|
22
20
|
app(:param_matchers) do |r|
|
23
21
|
r.get "signup", :param=>"email" do |email|
|
24
22
|
email
|
25
23
|
end
|
26
24
|
|
27
|
-
|
28
|
-
"No email"
|
29
|
-
end
|
25
|
+
"No email"
|
30
26
|
end
|
31
27
|
|
32
28
|
io = StringIO.new
|
@@ -34,4 +30,40 @@ describe "param_matchers plugin" do
|
|
34
30
|
body("/signup", "rack.input" => io, "QUERY_STRING" => "").must_equal 'No email'
|
35
31
|
body("/signup", "rack.input" => io, "QUERY_STRING" => "email=").must_equal ''
|
36
32
|
end
|
33
|
+
|
34
|
+
it "params! matcher should yield the params only if all are given and not empty" do
|
35
|
+
app(:param_matchers) do |r|
|
36
|
+
r.get "signup", :params! => %w"em ail" do |em, ail|
|
37
|
+
em + ail
|
38
|
+
end
|
39
|
+
|
40
|
+
"No email"
|
41
|
+
end
|
42
|
+
|
43
|
+
io = StringIO.new
|
44
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=john@doe.com").must_equal 'foojohn@doe.com'
|
45
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=john@doe.com").must_equal 'No email'
|
46
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=").must_equal 'No email'
|
47
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=").must_equal 'No email'
|
48
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo").must_equal 'No email'
|
49
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "ail=john@doe.com").must_equal 'No email'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "params matcher should yield the params only if all are given" do
|
53
|
+
app(:param_matchers) do |r|
|
54
|
+
r.get "signup", :params=>%w"em ail" do |em, ail|
|
55
|
+
em + ail
|
56
|
+
end
|
57
|
+
|
58
|
+
"No email"
|
59
|
+
end
|
60
|
+
|
61
|
+
io = StringIO.new
|
62
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=john@doe.com").must_equal 'foojohn@doe.com'
|
63
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=john@doe.com").must_equal 'john@doe.com'
|
64
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo&ail=").must_equal 'foo'
|
65
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=&ail=").must_equal ''
|
66
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "em=foo").must_equal 'No email'
|
67
|
+
body("/signup", "rack.input" => io, "QUERY_STRING" => "ail=john@doe.com").must_equal 'No email'
|
68
|
+
end
|
37
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -143,6 +143,7 @@ extra_rdoc_files:
|
|
143
143
|
- doc/release_notes/2.4.0.txt
|
144
144
|
- doc/release_notes/2.5.0.txt
|
145
145
|
- doc/release_notes/2.5.1.txt
|
146
|
+
- doc/release_notes/2.6.0.txt
|
146
147
|
files:
|
147
148
|
- CHANGELOG
|
148
149
|
- MIT-LICENSE
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- doc/release_notes/2.4.0.txt
|
161
162
|
- doc/release_notes/2.5.0.txt
|
162
163
|
- doc/release_notes/2.5.1.txt
|
164
|
+
- doc/release_notes/2.6.0.txt
|
163
165
|
- lib/roda.rb
|
164
166
|
- lib/roda/plugins/_erubis_escaping.rb
|
165
167
|
- lib/roda/plugins/all_verbs.rb
|
@@ -334,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
336
|
version: '0'
|
335
337
|
requirements: []
|
336
338
|
rubyforge_project:
|
337
|
-
rubygems_version: 2.4.5
|
339
|
+
rubygems_version: 2.4.5.1
|
338
340
|
signing_key:
|
339
341
|
specification_version: 4
|
340
342
|
summary: Routing tree web framework toolkit
|