rschema 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rschema/coercers/any.rb +4 -0
- data/lib/rschema/coercers/boolean.rb +4 -0
- data/lib/rschema/coercers/chain.rb +4 -0
- data/lib/rschema/coercers/date.rb +4 -0
- data/lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb +13 -1
- data/lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb +13 -1
- data/lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb +15 -3
- data/lib/rschema/coercers/fixed_hash/symbolize_keys.rb +11 -3
- data/lib/rschema/coercers/float.rb +4 -0
- data/lib/rschema/coercers/integer.rb +4 -0
- data/lib/rschema/coercers/nil_empty_strings.rb +5 -1
- data/lib/rschema/coercers/symbol.rb +4 -0
- data/lib/rschema/coercers/time.rb +4 -0
- data/lib/rschema/coercion_wrapper/rack_params.rb +2 -0
- data/lib/rschema/schemas/coercer.rb +5 -0
- data/lib/rschema/version.rb +1 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d720955c9a91f41ca082da8683dcf7bed5d10ab6
|
4
|
+
data.tar.gz: 6d374b1df2484fa2ec0957ca3d5943289ecb9714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2152a4189beed6ab21c9fd11afbf668b32cbca48eb58c89820b424473c83ac766e2819f49dc10e456690c4e75a7c2dcb3be1f52cfdc4e89528f34c01c0c45209
|
7
|
+
data.tar.gz: d4ccfbf1529449d6f13633898dde3c5c65f363ba041724503214e68f23720a02c2870c0b0215ed5fd3324e71ff6f49a590ac4eb2bd8c6e4973e9fc2b0ca732cf
|
data/lib/rschema/coercers/any.rb
CHANGED
@@ -26,9 +26,13 @@ module FixedHash
|
|
26
26
|
Result.success(default_arrays_to_empty(value))
|
27
27
|
end
|
28
28
|
|
29
|
+
def will_affect?(value)
|
30
|
+
keys_to_default(value).any?
|
31
|
+
end
|
32
|
+
|
29
33
|
private
|
30
34
|
def default_arrays_to_empty(hash)
|
31
|
-
missing_keys =
|
35
|
+
missing_keys = keys_to_default(hash)
|
32
36
|
|
33
37
|
if missing_keys.any?
|
34
38
|
defaults = missing_keys.map{ |k| [k, []] }.to_h
|
@@ -38,6 +42,14 @@ module FixedHash
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
45
|
+
def keys_to_default(value)
|
46
|
+
if value.is_a?(Hash)
|
47
|
+
keys_for_array_defaulting - value.keys
|
48
|
+
else
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
41
53
|
def keys_for_array_defaulting
|
42
54
|
@keys_for_array_defaulting ||= Set.new(
|
43
55
|
hash_attributes
|
@@ -25,9 +25,13 @@ module FixedHash
|
|
25
25
|
Result.success(default_bools_to_false(value))
|
26
26
|
end
|
27
27
|
|
28
|
+
def will_affect?(value)
|
29
|
+
keys_to_default(value).any?
|
30
|
+
end
|
31
|
+
|
28
32
|
private
|
29
33
|
def default_bools_to_false(hash)
|
30
|
-
missing_keys =
|
34
|
+
missing_keys = keys_to_default(hash)
|
31
35
|
|
32
36
|
if missing_keys.any?
|
33
37
|
defaults = missing_keys.map{ |k| [k, false] }.to_h
|
@@ -37,6 +41,14 @@ module FixedHash
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
def keys_to_default(value)
|
45
|
+
if value.is_a?(Hash)
|
46
|
+
keys_for_bool_defaulting - value.keys
|
47
|
+
else
|
48
|
+
[]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def keys_for_bool_defaulting
|
41
53
|
@keys_for_bool_defaulting ||= Set.new(
|
42
54
|
hash_attributes
|
@@ -18,20 +18,32 @@ module FixedHash
|
|
18
18
|
Result.success(remove_extraneous_elements(value))
|
19
19
|
end
|
20
20
|
|
21
|
+
def will_affect?(value)
|
22
|
+
keys_to_remove(value).any?
|
23
|
+
end
|
24
|
+
|
21
25
|
private
|
22
26
|
|
23
27
|
def remove_extraneous_elements(hash)
|
24
|
-
|
28
|
+
extra_keys = keys_to_remove(hash)
|
25
29
|
|
26
|
-
if
|
30
|
+
if extra_keys.any?
|
27
31
|
hash.dup.tap do |stripped_hash|
|
28
|
-
|
32
|
+
extra_keys.each { |k| stripped_hash.delete(k) }
|
29
33
|
end
|
30
34
|
else
|
31
35
|
hash
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
39
|
+
def keys_to_remove(value)
|
40
|
+
if value.is_a?(Hash)
|
41
|
+
value.keys - valid_keys
|
42
|
+
else
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
def valid_keys
|
36
48
|
@valid_keys ||= hash_attributes.map(&:key)
|
37
49
|
end
|
@@ -20,6 +20,10 @@ module FixedHash
|
|
20
20
|
Result.success(symbolize_keys(value))
|
21
21
|
end
|
22
22
|
|
23
|
+
def will_affect?(value)
|
24
|
+
keys_to_symbolize(hash).any?
|
25
|
+
end
|
26
|
+
|
23
27
|
private
|
24
28
|
|
25
29
|
def symbolize_keys(hash)
|
@@ -33,9 +37,13 @@ module FixedHash
|
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
|
-
def keys_to_symbolize(
|
37
|
-
|
38
|
-
|
40
|
+
def keys_to_symbolize(value)
|
41
|
+
if value.is_a?(Hash)
|
42
|
+
non_string_keys = Set.new(value.keys) - string_keys
|
43
|
+
non_string_keys.intersection(symbol_keys_as_strings)
|
44
|
+
else
|
45
|
+
[]
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
def symbol_keys_as_strings
|
@@ -9,12 +9,16 @@ module Coercers
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(value)
|
12
|
-
if
|
12
|
+
if "" == value
|
13
13
|
Result.success(nil)
|
14
14
|
else
|
15
15
|
Result.success(value)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def will_affect?(value)
|
20
|
+
"" == value
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
@@ -18,6 +18,11 @@ class Coercer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def call(value, options)
|
21
|
+
unless coercer.will_affect?(value)
|
22
|
+
# short-circuit the coercer
|
23
|
+
return @subschema.call(value, options)
|
24
|
+
end
|
25
|
+
|
21
26
|
result = coercer.call(value)
|
22
27
|
if result.valid?
|
23
28
|
@subschema.call(result.value, options)
|
data/lib/rschema/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rschema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Dalling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docile
|
@@ -108,6 +108,48 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: benchmark-ips
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activemodel
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: dry-validation
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
111
153
|
description: |2
|
112
154
|
Schema-based validation and coercion for Ruby data structures, inspired
|
113
155
|
by Prismatic/schema for Clojure.
|