paramore 3.9.2 → 3.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paramore/cast_parameters.rb +39 -35
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e0c787e647893bfc2aff716c26dc1451de26f947e372106e1888776926e22d
|
4
|
+
data.tar.gz: 79a9c035350ec1519c5a1ca546fbaca6c30c97047f101fc94bbdd4eccf1cf593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63fa1693e3a7031ed28af6c9eb0d7f960cd1f42562325e4f5bef6e38bb4231f1708b9923872f5d1cb36de17a2cdff2a2556bba850f6d62ceacde007f418bd82c
|
7
|
+
data.tar.gz: ac1f5eff659d7bbcfb0a723ea4d5a216486e805744aef060780e8d799ac1c859e3111bd0e8b9a52cd71388a7594fe396598ed70c2f28f7eff9135dc4017ab03c
|
@@ -15,81 +15,85 @@ module Paramore
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def run
|
18
|
-
cast(root_field, data, '
|
18
|
+
cast(root_field, data, 'root')
|
19
19
|
end
|
20
20
|
|
21
|
-
def cast(field, value,
|
21
|
+
def cast(field, value, key, namespace = nil)
|
22
|
+
full_name = [namespace, key].compact.join('.')
|
23
|
+
|
22
24
|
if value.nil?
|
23
|
-
if field.nullable? || field.default?
|
24
|
-
|
25
|
-
|
26
|
-
raise Paramore::NilParameter, name
|
27
|
-
end
|
25
|
+
return field.default if field.nullable? || field.default?
|
26
|
+
|
27
|
+
raise Paramore::NilParameter, full_name
|
28
28
|
elsif value == ''
|
29
|
-
if field.allow_empty?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
return
|
35
|
-
else
|
36
|
-
raise Paramore::NilParameter, name
|
37
|
-
end
|
29
|
+
return typecast_value(field.type, '', key, full_name) if field.allow_empty?
|
30
|
+
return field.default if field.default?
|
31
|
+
return if field.nullable?
|
32
|
+
|
33
|
+
raise Paramore::NilParameter, full_name
|
38
34
|
end
|
39
35
|
|
40
36
|
case field.type
|
41
37
|
when Hash
|
42
|
-
typecast_hash(field, value || {},
|
38
|
+
typecast_hash(field, value || {}, key, full_name)
|
43
39
|
when Array
|
44
|
-
typecast_array(field, value,
|
40
|
+
typecast_array(field, value, key, full_name)
|
45
41
|
else
|
46
|
-
typecast_value(field.type, value,
|
42
|
+
typecast_value(field.type, value, key, full_name)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
50
|
-
def typecast_hash(field, hash,
|
51
|
-
raise Paramore::HashExpected.new(
|
46
|
+
def typecast_hash(field, hash, key, full_name)
|
47
|
+
raise Paramore::HashExpected.new(full_name, hash) unless hash.is_a?(Hash)
|
52
48
|
|
53
49
|
result =
|
54
50
|
if field.wildly_keyed_hash?
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
[field.type.values.first, field.type.keys.first].then do |value_field, key_type|
|
52
|
+
hash.to_h do |inner_key, value|
|
53
|
+
[
|
54
|
+
typecast_value(key_type, inner_key, nil, nil),
|
55
|
+
cast(value_field, value, inner_key, full_name)
|
56
|
+
]
|
57
|
+
end
|
59
58
|
end
|
60
59
|
else
|
61
60
|
if options[:no_extra_keys]
|
62
61
|
extra = hash.keys - field.type.keys
|
63
|
-
raise "Found extra keys in `#{
|
62
|
+
raise "Found extra keys in `#{full_name}`: #{extra}!" if extra.any?
|
64
63
|
end
|
65
64
|
|
66
65
|
field
|
67
66
|
.type
|
68
|
-
.reject { |
|
69
|
-
.to_h
|
67
|
+
.reject { |inner_key, value_field| missing_and_optional?(hash, inner_key, value_field) }
|
68
|
+
.to_h do |inner_key, value_field|
|
69
|
+
[
|
70
|
+
inner_key,
|
71
|
+
cast(value_field, hash[inner_key], inner_key, full_name)
|
72
|
+
]
|
73
|
+
end
|
70
74
|
end
|
71
75
|
|
72
76
|
field.compact? ? result.compact : result
|
73
77
|
end
|
74
78
|
|
75
|
-
def typecast_array(field, array,
|
76
|
-
raise Paramore::ArrayExpected.new(
|
79
|
+
def typecast_array(field, array, key, full_name)
|
80
|
+
raise Paramore::ArrayExpected.new(full_name, array) unless array.is_a?(Array)
|
77
81
|
|
78
82
|
result = array
|
79
83
|
.reject { |unit| unit.to_s == '' && field.compact? }
|
80
|
-
.map { |unit| cast(Paramore.field(field.type.first, null: true), unit) }
|
84
|
+
.map { |unit| cast(Paramore.field(field.type.first, null: true), unit, nil, full_name) }
|
81
85
|
|
82
86
|
field.compact? ? result.compact : result
|
83
87
|
end
|
84
88
|
|
85
|
-
def typecast_value(type, value,
|
89
|
+
def typecast_value(type, value, key, full_name)
|
86
90
|
type.send(Paramore.configuration.type_method_name, value)
|
87
91
|
rescue StandardError => e
|
88
|
-
raise "The field `#{
|
92
|
+
raise "The field `#{full_name}` raised \"#{e}\"!"
|
89
93
|
end
|
90
94
|
|
91
|
-
def missing_and_optional?(hash,
|
92
|
-
!hash.key?(
|
95
|
+
def missing_and_optional?(hash, key, field)
|
96
|
+
!hash.key?(key) && !field.required?
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paramore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.9.
|
4
|
+
version: 3.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Kairevičius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -115,7 +115,7 @@ licenses:
|
|
115
115
|
- MIT
|
116
116
|
metadata: {}
|
117
117
|
post_install_message: |
|
118
|
-
Thank you for installing Paramore 3.9.
|
118
|
+
Thank you for installing Paramore 3.9.3 !
|
119
119
|
From the command line you can run `paramore` to generate a configuration file
|
120
120
|
|
121
121
|
More details here : https://github.com/lumzdas/paramore/blob/master/README.md
|