tainted_params 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -13
- data/lib/tainted_params/core_ext/hash.rb +4 -4
- data/lib/tainted_params/string_key_hash.rb +26 -1
- data/lib/tainted_params/version.rb +1 -1
- data/spec/unit/string_key_hash_spec.rb +47 -3
- 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: 850558584222bbe91bd8409f4b35900f4f9bfc3a
|
4
|
+
data.tar.gz: 20172f254c3c3c389981167118d69e8d84c39c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3696a33659110c78cf3ef2f453a4cc3d12a3ad9f842e2338a13a12b025f39948a96a82e8f1230793517ce9fbce30f5ddee551bfaee192ad9f05722dd3e5639e6
|
7
|
+
data.tar.gz: 1ad9fbb6bc9bb3857ec67cd070766979df0b240b277225a92f94166860e0946b6b4699d40d3022d6731609b651fd3f9b4d3cef970efd4ec2aa711811159f6f78
|
data/README.md
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
https://github.com/Ragmaanir/tainted_params
|
4
4
|
|
5
|
-
|
5
|
+
## Description
|
6
6
|
|
7
7
|
Behaves like strong_parameters, with some minor differences.
|
8
8
|
|
9
|
-
|
9
|
+
## Features
|
10
10
|
|
11
11
|
- Validate required and optional parameters
|
12
12
|
- Validate their types
|
13
13
|
- Type coercions for parameters
|
14
14
|
|
15
|
-
|
15
|
+
## Problems/Todo
|
16
16
|
|
17
17
|
- made some monkey patches to hash(slice, only, except, map_pairs) to not having to depend on active support gem
|
18
18
|
- custom HashWithIndifferentAccess
|
19
19
|
|
20
|
-
|
20
|
+
## Synopsis
|
21
21
|
|
22
22
|
builder = TaintedParams::ParamsValidatorBuilder.new do
|
23
23
|
required :id, :Integer
|
@@ -31,20 +31,21 @@ Behaves like strong_parameters, with some minor differences.
|
|
31
31
|
|
32
32
|
result = validator.validate(options: { name: 'bob', active: 1, admin: true })
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# These evaluate to true:
|
35
|
+
result.valid == { options: { name: 'bob' } }
|
36
|
+
result.invalid == { options: { active: 1 } }
|
37
|
+
result.unpermitted == { options: { admin: true } }
|
38
|
+
result.missing == { id: nil }
|
38
39
|
|
39
|
-
|
40
|
+
## Requirements
|
40
41
|
|
41
42
|
* Ruby >= 2
|
42
43
|
|
43
|
-
|
44
|
+
## Install
|
44
45
|
|
45
46
|
* FIX
|
46
47
|
|
47
|
-
|
48
|
+
## Developers
|
48
49
|
|
49
50
|
After checking out the source, run:
|
50
51
|
|
@@ -53,11 +54,11 @@ After checking out the source, run:
|
|
53
54
|
This task will install any missing dependencies, run the tests/specs,
|
54
55
|
and generate the RDoc.
|
55
56
|
|
56
|
-
|
57
|
+
## Internals
|
57
58
|
|
58
59
|
The ParamsValidatorBuilder constructs a ParamsValidator out of ParamConstraints. The ParamsValidator contains the validation logic to split a params-hash into valid, invalid, missing and unpermitted parts.
|
59
60
|
|
60
|
-
|
61
|
+
## License
|
61
62
|
|
62
63
|
(The MIT License)
|
63
64
|
|
@@ -16,11 +16,11 @@ class Hash
|
|
16
16
|
# end
|
17
17
|
# end
|
18
18
|
|
19
|
-
def slice(keys)
|
20
|
-
|
21
|
-
end
|
19
|
+
# def slice(keys)
|
20
|
+
# select{ |k,_| keys.include?(k) }
|
21
|
+
# end
|
22
22
|
|
23
|
-
alias_method :only, :slice
|
23
|
+
#alias_method :only, :slice
|
24
24
|
|
25
25
|
def except(keys)
|
26
26
|
select{ |k,_| !keys.include?(k) }
|
@@ -17,12 +17,29 @@ module TaintedParams
|
|
17
17
|
@hash = self.class.stringify_keys(hash).freeze
|
18
18
|
end
|
19
19
|
|
20
|
-
def_delegators :@hash,
|
20
|
+
def_delegators :@hash, *%w{
|
21
|
+
fetch
|
22
|
+
keys values rassoc shift
|
23
|
+
each map_pairs
|
24
|
+
length size empty?
|
25
|
+
}
|
26
|
+
|
27
|
+
def key?(k)
|
28
|
+
@hash.key?(convert_key(k))
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :include?, :key?
|
32
|
+
alias_method :has_key?, :key?
|
33
|
+
alias_method :member?, :key?
|
21
34
|
|
22
35
|
def [](key)
|
23
36
|
@hash[convert_key(key)]
|
24
37
|
end
|
25
38
|
|
39
|
+
def values_at(*args)
|
40
|
+
args.map{ |k| self[k] }
|
41
|
+
end
|
42
|
+
|
26
43
|
def merge(hash, &block)
|
27
44
|
self.class.new(self.to_hash.merge(hash, &block))
|
28
45
|
end
|
@@ -35,6 +52,14 @@ module TaintedParams
|
|
35
52
|
@hash
|
36
53
|
end
|
37
54
|
|
55
|
+
def ==(other)
|
56
|
+
case other
|
57
|
+
when Hash then self == self.class.new(other)
|
58
|
+
when self.class then to_hash == other.to_hash
|
59
|
+
else false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
38
63
|
private
|
39
64
|
|
40
65
|
def convert_key(key)
|
@@ -2,18 +2,62 @@ describe TaintedParams::StringKeyHash do
|
|
2
2
|
|
3
3
|
let(:h) { described_class.new(symbol: 1, 'string' => 2) }
|
4
4
|
|
5
|
-
it '' do
|
5
|
+
it '#respond_to?' do
|
6
|
+
%w{
|
7
|
+
fetch [] key? member? include? has_key? shift
|
8
|
+
each
|
9
|
+
length size empty? any?
|
10
|
+
map select reject map collect
|
11
|
+
values_at merge keys rassoc dup ==}.each do |meth|
|
12
|
+
assert{ h.respond_to?(meth) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#[]' do
|
6
17
|
assert{ h['symbol'] == 1 }
|
7
18
|
assert{ h[:string] == 2 }
|
8
19
|
end
|
9
20
|
|
10
|
-
it '' do
|
21
|
+
it '#each' do
|
22
|
+
res = {}
|
23
|
+
h.each do |k,v|
|
24
|
+
res[k] = v
|
25
|
+
end
|
26
|
+
|
27
|
+
assert{ res == {'symbol' => 1, 'string' => 2} }
|
28
|
+
end
|
29
|
+
|
30
|
+
it '#select' do
|
31
|
+
res = h.select{ |k,v| v > 1 }
|
32
|
+
assert{ res == [['string', 2]] }
|
33
|
+
end
|
34
|
+
|
35
|
+
it '#map' do
|
36
|
+
res = h.map{ |k,v| [k, v + 1] }
|
37
|
+
assert{ res == [['symbol', 2], ['string', 3]] }
|
38
|
+
end
|
39
|
+
|
40
|
+
it '#values_at' do
|
41
|
+
assert{ h.values_at(:symbol, 'string') == [1,2] }
|
42
|
+
end
|
43
|
+
|
44
|
+
it '#merge' do
|
11
45
|
h2 = h.merge(newsymbol: 3)
|
46
|
+
assert{ h2.is_a?(described_class) }
|
12
47
|
assert{ h2['newsymbol'] == 3 }
|
13
48
|
end
|
14
49
|
|
15
|
-
it '' do
|
50
|
+
it '#keys' do
|
16
51
|
assert{ h.keys == ['symbol', 'string'] }
|
17
52
|
end
|
18
53
|
|
54
|
+
it '#rassoc' do
|
55
|
+
assert{ h.rassoc(1) == ['symbol', 1] }
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#==' do
|
59
|
+
assert{ h == {symbol: 1, 'string' => 2} }
|
60
|
+
assert{ h == {'symbol' => 1, 'string' => 2} }
|
61
|
+
end
|
62
|
+
|
19
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tainted_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ragmaanir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|