smart_params 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smart_params/field.rb +16 -13
- data/lib/smart_params/version.rb +1 -1
- data/lib/smart_params.rb +1 -1
- data/lib/smart_params_spec.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54e6652607fb402ff6368c2b0dc8d16c8b4fce3e45b0ad0aeb4d74ecc1798ab8
|
4
|
+
data.tar.gz: 4c829acd140f7758ee9a8828a4627a554020b5f05773fea748440578d4506120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f677d9c2c58724cb79a796665f987b2a5a9e7390f17b625b7dfac49907dd611bbbb7541d1b65d0fe1d98f13d4e68eeb03d1eb97cdeb3cfb90dd7c950777759
|
7
|
+
data.tar.gz: 4bb161323aafc93aab63636dd32713dc42b37dd8a2a14e9bd6a5821cf52106d61b79437eb1412b2501d3a67de4790d17b7ecc2c280654d128c6cdd0edb19a022
|
data/lib/smart_params/field.rb
CHANGED
@@ -7,8 +7,7 @@ module SmartParams
|
|
7
7
|
attr_reader :subfields
|
8
8
|
attr_reader :type
|
9
9
|
|
10
|
-
def initialize(keychain:, type:,
|
11
|
-
@root = root
|
10
|
+
def initialize(keychain:, type:, &nesting)
|
12
11
|
@keychain = Array(keychain)
|
13
12
|
@subfields = Set.new
|
14
13
|
@type = type
|
@@ -18,18 +17,14 @@ module SmartParams
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
def field(key, type:, &subfield)
|
22
|
-
@subfields << self.class.new(keychain: [*keychain, key], type: type, &subfield)
|
23
|
-
end
|
24
|
-
|
25
20
|
def deep?
|
26
21
|
subfields.present?
|
27
22
|
end
|
28
23
|
|
29
24
|
def claim(raw)
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
return type[dug(raw)] if deep?
|
26
|
+
|
27
|
+
@value = type[dug(raw)]
|
33
28
|
rescue Dry::Types::ConstraintError => bad_type_exception
|
34
29
|
raise SmartParams::Error::InvalidPropertyType, keychain: keychain, wanted: type, raw: if keychain.empty? then raw else raw.dig(*keychain) end
|
35
30
|
end
|
@@ -49,12 +44,20 @@ module SmartParams
|
|
49
44
|
value.nil?
|
50
45
|
end
|
51
46
|
|
52
|
-
def
|
53
|
-
|
47
|
+
def weight
|
48
|
+
keychain
|
54
49
|
end
|
55
50
|
|
56
|
-
def
|
57
|
-
keychain
|
51
|
+
private def field(key, type:, &subfield)
|
52
|
+
@subfields << self.class.new(keychain: [*keychain, key], type: type, &subfield)
|
53
|
+
end
|
54
|
+
|
55
|
+
private def dug(raw)
|
56
|
+
if keychain.empty?
|
57
|
+
raw
|
58
|
+
else
|
59
|
+
raw.dig(*keychain)
|
60
|
+
end
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/lib/smart_params/version.rb
CHANGED
data/lib/smart_params.rb
CHANGED
data/lib/smart_params_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|