roda 3.13.0 → 3.14.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/doc/release_notes/3.14.0.txt +36 -0
- data/lib/roda/plugins/typecast_params.rb +20 -7
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/mailer_spec.rb +3 -3
- data/spec/plugin/typecast_params_spec.rb +69 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc2076279138faeeae9396e6cb397e5661de1ebe90517dc8bfcc0ab69c1c6a66
|
4
|
+
data.tar.gz: dbbd9323a8b414de60b4d2f4a6c5ca63ca7fbbf0cd4f9015fbbf82973500a8d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad3f3d6d15bdcf8d146a8f44f3f3a4e1599dd7ec15e0aa3b7a912e61fea72a7cb3d1d631f9c9943abf43a796bfd38c18a44184579f13456c2b943cdf3cf3f272
|
7
|
+
data.tar.gz: affb16c92264210bbbe62a4f059012a4242f821bef661c308050bb36815f5885eaa3c0dc0c59d312390330dcda91de511a8413be109608e1f39bce641d97c78b
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 3.14.0 (2018-11-16)
|
2
|
+
|
3
|
+
* Add :raise option to convert!/convert_each! in the typecast_params plugin to support not raising for missing keys (celsworth) (#153)
|
4
|
+
|
5
|
+
* Do not persist convert!/convert_each! :symbolize setting in the typecast_params plugin (jeremyevans)
|
6
|
+
|
1
7
|
= 3.13.0 (2018-10-12)
|
2
8
|
|
3
9
|
* Make Stream#write in streaming plugin return number of bytes written instead of self, so it works with IO.copy_stream (jeremyevans)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* The convert! and convert_each! methods in the typecast_params plugin
|
4
|
+
now support a :raise option for handling missing parameters specified
|
5
|
+
as arguments to the methods.
|
6
|
+
|
7
|
+
If the :raise option is set to false for convert! and the parameter
|
8
|
+
argument is missing, then no conversion is done and an empty hash
|
9
|
+
is returned:
|
10
|
+
|
11
|
+
typecast_params.convert!('missing', raise: false) do |tp|
|
12
|
+
# ...
|
13
|
+
end
|
14
|
+
# => {}
|
15
|
+
|
16
|
+
If the :raise option is set to false for convert_each! and a :keys
|
17
|
+
option is given, any key not present is ignored and nil will be
|
18
|
+
returned for the converted value
|
19
|
+
|
20
|
+
typecast_params.convert_each!(:keys=>['present', 'missing'], raise: false) do |tp|
|
21
|
+
tp.int('b')
|
22
|
+
end
|
23
|
+
# => [{'b'=>1}, nil]
|
24
|
+
|
25
|
+
= Other Improvements
|
26
|
+
|
27
|
+
* The :symbolize setting to the convert! and convert_each! methods in
|
28
|
+
the typecast_params plugin is no longer persisted beyond the call
|
29
|
+
to the method. This fixes unexpected behavior if you do:
|
30
|
+
|
31
|
+
typecast_params.convert!(:symbolize=>true) do |tp|
|
32
|
+
# ...
|
33
|
+
end
|
34
|
+
typecast_params.convert! do |tp|
|
35
|
+
# ...
|
36
|
+
end
|
@@ -572,6 +572,7 @@ class Roda
|
|
572
572
|
# or nil to convert the current object. If +keys+ is given as a hash, it is used as
|
573
573
|
# the options hash. Options:
|
574
574
|
#
|
575
|
+
# :raise :: If set to false, do not raise errors for missing keys
|
575
576
|
# :symbolize :: Convert any string keys in the resulting hash and for any
|
576
577
|
# conversions below
|
577
578
|
def convert!(keys=nil, opts=OPTS)
|
@@ -581,19 +582,19 @@ class Roda
|
|
581
582
|
end
|
582
583
|
|
583
584
|
_capture!(:nested_params, opts) do
|
584
|
-
if sub = subkey(Array(keys).dup, true)
|
585
|
+
if sub = subkey(Array(keys).dup, opts.fetch(:raise, true))
|
585
586
|
yield sub
|
586
587
|
end
|
587
588
|
end
|
588
589
|
end
|
589
590
|
|
590
|
-
# Runs convert! for each key specified by the :keys option. If :keys option is not given
|
591
|
-
# and the object is an array, runs
|
591
|
+
# Runs conversions similar to convert! for each key specified by the :keys option. If :keys option is not given
|
592
|
+
# and the object is an array, runs conversions for all entries in the array. If the :keys
|
592
593
|
# option is not given and the object is a Hash with string keys '0', '1', ..., 'N' (with
|
593
|
-
# no skipped keys), runs
|
594
|
+
# no skipped keys), runs conversions for all entries in the hash. If :keys option is a Proc
|
594
595
|
# or a Method, calls the proc/method with the current object, which should return an
|
595
596
|
# array of keys to use.
|
596
|
-
#
|
597
|
+
# Supports options given to #convert!, and this additional option:
|
597
598
|
#
|
598
599
|
# :keys :: The keys to extract from the object. If a proc or method,
|
599
600
|
# calls the value with the current object, which should return the array of keys
|
@@ -628,7 +629,7 @@ class Roda
|
|
628
629
|
|
629
630
|
keys.map do |i|
|
630
631
|
begin
|
631
|
-
if v = subkey([i], true)
|
632
|
+
if v = subkey([i], opts.fetch(:raise, true))
|
632
633
|
yield v
|
633
634
|
v.nested_params if np
|
634
635
|
end
|
@@ -692,6 +693,8 @@ class Roda
|
|
692
693
|
|
693
694
|
# Recursively descendent into all known subkeys and get the converted params from each.
|
694
695
|
def nested_params
|
696
|
+
return @nested_params if @nested_params
|
697
|
+
|
695
698
|
params = @params
|
696
699
|
|
697
700
|
if @subs
|
@@ -762,6 +765,8 @@ class Roda
|
|
762
765
|
|
763
766
|
# Internals of convert! and convert_each!.
|
764
767
|
def _capture!(ret, opts)
|
768
|
+
previous_symbolize = @symbolize
|
769
|
+
|
765
770
|
unless cap = @capture
|
766
771
|
@params = @obj.class.new
|
767
772
|
@subs.clear if @subs
|
@@ -793,10 +798,18 @@ class Roda
|
|
793
798
|
end
|
794
799
|
end
|
795
800
|
ensure
|
796
|
-
|
801
|
+
@nested_params = nil
|
802
|
+
|
797
803
|
if capturing_started
|
804
|
+
# Unset capturing if capturing was not already started.
|
798
805
|
@capture = nil
|
806
|
+
else
|
807
|
+
# If capturing was already started, update cached nested params
|
808
|
+
# before resetting symbolize setting.
|
809
|
+
@nested_params = nested_params
|
799
810
|
end
|
811
|
+
|
812
|
+
@symbolize = previous_symbolize
|
800
813
|
end
|
801
814
|
|
802
815
|
# Raise an error if the array given does contains nil values.
|
data/lib/roda/version.rb
CHANGED
data/spec/plugin/mailer_spec.rb
CHANGED
@@ -102,7 +102,7 @@ describe "mailer plugin" do
|
|
102
102
|
m.attachments.first.content_type.must_match(/mailer_spec\.rb/)
|
103
103
|
m.content_type.must_match(/\Amultipart\/mixed/)
|
104
104
|
m.parts.length.must_equal 1
|
105
|
-
m.parts.first.body.
|
105
|
+
m.parts.first.body.decoded.gsub("\r\n", "\n").must_equal File.read(__FILE__)
|
106
106
|
end
|
107
107
|
|
108
108
|
it "supports attachments with blocks" do
|
@@ -120,7 +120,7 @@ describe "mailer plugin" do
|
|
120
120
|
m.attachments.first.content_type.must_equal 'text/foo'
|
121
121
|
m.content_type.must_match(/\Amultipart\/mixed/)
|
122
122
|
m.parts.length.must_equal 1
|
123
|
-
m.parts.first.body.
|
123
|
+
m.parts.first.body.decoded.gsub("\r\n", "\n").must_equal File.read(__FILE__)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "supports plain-text attachments with an email body" do
|
@@ -242,7 +242,7 @@ describe "mailer plugin" do
|
|
242
242
|
m.parts.first.content_type.must_match(/\Atext\/html/)
|
243
243
|
m.parts.first.body.must_be :==, "a"
|
244
244
|
m.parts.last.content_type.must_match(/\Atext\/css/)
|
245
|
-
m.parts.last.body.
|
245
|
+
m.parts.last.body.decoded.gsub("\r\n", "\n").must_equal File.read('spec/assets/css/raw.css')
|
246
246
|
end
|
247
247
|
end
|
248
248
|
end
|
@@ -530,6 +530,24 @@ describe "typecast_params plugin" do
|
|
530
530
|
end.must_equal('a'=>[{'b'=>[{'e'=>1}]}])
|
531
531
|
end
|
532
532
|
|
533
|
+
it "#convert! should not raise errors for missing keys if :raise option is false" do
|
534
|
+
tp = tp('a[b]=1')
|
535
|
+
tp.convert! do |tp0|
|
536
|
+
tp0.convert!('a') do |tp1|
|
537
|
+
tp1.convert!('c', :raise=>false) do |tp2|
|
538
|
+
tp2.convert!('d') do |tp2|
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end.must_equal('a'=>{})
|
543
|
+
|
544
|
+
tp.convert!('b', :raise=>false){}.must_equal({})
|
545
|
+
|
546
|
+
tp.convert!('b', :raise=>false) do |tp0|
|
547
|
+
tp1.convert!('c'){}
|
548
|
+
end.must_equal({})
|
549
|
+
end
|
550
|
+
|
533
551
|
it "#convert! should handle #[] without #convert! at each level" do
|
534
552
|
tp = tp('a[b][c][d][e]=1')
|
535
553
|
tp.convert! do |tp0|
|
@@ -585,6 +603,19 @@ describe "typecast_params plugin" do
|
|
585
603
|
end.must_equal('a'=>[1], 'd'=>[2], 'g'=>[nil])
|
586
604
|
end
|
587
605
|
|
606
|
+
it "#convert! should handle multiple convert! calls inside" do
|
607
|
+
tp = tp('a[b]=1&c[d]=2')
|
608
|
+
tp.convert! do |tp0|
|
609
|
+
tp0.convert!('a'){|d| d.int('b')}
|
610
|
+
tp0.convert!('c'){|d| d.int('d')}
|
611
|
+
end.must_equal('a'=>{'b'=>1}, 'c'=>{'d'=>2})
|
612
|
+
|
613
|
+
tp.convert!(:symbolize=>true) do |tp0|
|
614
|
+
tp0.convert!('a'){|d| d.int('b')}
|
615
|
+
tp0.convert!('c'){|d| d.int('d')}
|
616
|
+
end.must_equal(:a=>{:b=>1}, :c=>{:d=>2})
|
617
|
+
end
|
618
|
+
|
588
619
|
it "#convert_each! should convert each entry in an array" do
|
589
620
|
tp = tp('a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4')
|
590
621
|
tp['a'].convert_each! do |tp0|
|
@@ -652,6 +683,13 @@ describe "typecast_params plugin" do
|
|
652
683
|
lambda{tp['b'].convert_each!{}}.must_raise @tp_error
|
653
684
|
end
|
654
685
|
|
686
|
+
it "#convert_each! should not raise errors for missing keys if :raise option is false" do
|
687
|
+
tp = tp('a[0][b]=1&a[0][c]=2&a[1][b]=3&a[1][c]=4')
|
688
|
+
tp['a'].convert_each!(:keys=>%w'0 2', :raise=>false) do |tp0|
|
689
|
+
tp0.int(%w'b c')
|
690
|
+
end.must_equal [{'b'=>1, 'c'=>2}, nil]
|
691
|
+
end
|
692
|
+
|
655
693
|
it "#convert! with :symbolize option should return a hash of converted parameters" do
|
656
694
|
tp = tp()
|
657
695
|
tp.convert!(:symbolize=>true) do |ptp|
|
@@ -663,6 +701,25 @@ describe "typecast_params plugin" do
|
|
663
701
|
end.must_equal(:a=>1, :b=>[2, 3], :c=>{:d=>4, :e=>5})
|
664
702
|
end
|
665
703
|
|
704
|
+
it "#convert! with :symbolize option should not persist" do
|
705
|
+
tp = tp()
|
706
|
+
tp.convert!(:symbolize=>true) do |ptp|
|
707
|
+
ptp.int!('a')
|
708
|
+
ptp.array!(:int, 'b')
|
709
|
+
ptp['c'].convert! do |stp|
|
710
|
+
stp.int!(%w'd e')
|
711
|
+
end
|
712
|
+
end.must_equal(:a=>1, :b=>[2, 3], :c=>{:d=>4, :e=>5})
|
713
|
+
|
714
|
+
tp.convert! do |ptp|
|
715
|
+
ptp.int!('a')
|
716
|
+
ptp.array!(:int, 'b')
|
717
|
+
ptp['c'].convert! do |stp|
|
718
|
+
stp.int!(%w'd e')
|
719
|
+
end
|
720
|
+
end.must_equal("a"=>1, "b"=>[2, 3], "c"=>{"d"=>4, "e"=>5})
|
721
|
+
end
|
722
|
+
|
666
723
|
it "#convert! with :symbolize option hash should only include changes made inside block" do
|
667
724
|
tp = tp()
|
668
725
|
tp.convert!(:symbolize=>true) do |ptp|
|
@@ -782,6 +839,18 @@ describe "typecast_params plugin" do
|
|
782
839
|
end.must_equal(:a=>{:'0'=>{:b=>1, :c=>2}, :'1'=>{:b=>3, :c=>4}})
|
783
840
|
end
|
784
841
|
|
842
|
+
it "#convert_each! with :symbolize option should not persist" do
|
843
|
+
tp = tp('a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4')
|
844
|
+
tp['a'].convert_each!(:symbolize=>true) do |tp0|
|
845
|
+
tp0.int(%w'b c')
|
846
|
+
end.must_equal [{:b=>1, :c=>2}, {:b=>3, :c=>4}]
|
847
|
+
|
848
|
+
tp = tp('a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4')
|
849
|
+
tp['a'].convert_each! do |tp0|
|
850
|
+
tp0.int(%w'b c')
|
851
|
+
end.must_equal [{'b'=>1, 'c'=>2}, {'b'=>3, 'c'=>4}]
|
852
|
+
end
|
853
|
+
|
785
854
|
it "#convert! with :symbolize options specified at different levels should work" do
|
786
855
|
tp = tp('a[b][c][d][e]=1')
|
787
856
|
tp.convert!(:symbolize=>true) do |tp0|
|
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: 3.
|
4
|
+
version: 3.14.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: 2018-
|
11
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -209,6 +209,7 @@ extra_rdoc_files:
|
|
209
209
|
- doc/release_notes/3.11.0.txt
|
210
210
|
- doc/release_notes/3.12.0.txt
|
211
211
|
- doc/release_notes/3.13.0.txt
|
212
|
+
- doc/release_notes/3.14.0.txt
|
212
213
|
files:
|
213
214
|
- CHANGELOG
|
214
215
|
- MIT-LICENSE
|
@@ -256,6 +257,7 @@ files:
|
|
256
257
|
- doc/release_notes/3.11.0.txt
|
257
258
|
- doc/release_notes/3.12.0.txt
|
258
259
|
- doc/release_notes/3.13.0.txt
|
260
|
+
- doc/release_notes/3.14.0.txt
|
259
261
|
- doc/release_notes/3.2.0.txt
|
260
262
|
- doc/release_notes/3.3.0.txt
|
261
263
|
- doc/release_notes/3.4.0.txt
|