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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43b4b84cd337c3737f9f83d70a8e64d3a95e0e08a4106eca29bd0c00cceedcf9
4
- data.tar.gz: 6e303c416ae81b6e933a4d7a3fb4e497746c1968f4730e317c8cab253c62805e
3
+ metadata.gz: 54e6652607fb402ff6368c2b0dc8d16c8b4fce3e45b0ad0aeb4d74ecc1798ab8
4
+ data.tar.gz: 4c829acd140f7758ee9a8828a4627a554020b5f05773fea748440578d4506120
5
5
  SHA512:
6
- metadata.gz: bb603816b69b989284b538ab7fe95e82418652f3560b0100071329a3f0e1fe6013a7e3318d2c9432847905c5600dae5aaed52a9dfef55d7dbf27e98b4746e122
7
- data.tar.gz: 2cdfa446d1c492e786087390d1220cac38b5f6f2fee75e234427e9b6c8e58d25f2a590b12c3af4d3b7fd027cd4610bde849f3da0da6f2e29bc034da956f25cfc
6
+ metadata.gz: 51f677d9c2c58724cb79a796665f987b2a5a9e7390f17b625b7dfac49907dd611bbbb7541d1b65d0fe1d98f13d4e68eeb03d1eb97cdeb3cfb90dd7c950777759
7
+ data.tar.gz: 4bb161323aafc93aab63636dd32713dc42b37dd8a2a14e9bd6a5821cf52106d61b79437eb1412b2501d3a67de4790d17b7ecc2c280654d128c6cdd0edb19a022
@@ -7,8 +7,7 @@ module SmartParams
7
7
  attr_reader :subfields
8
8
  attr_reader :type
9
9
 
10
- def initialize(keychain:, type:, root: false, &nesting)
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
- unless root?
31
- @value = type[if keychain.empty? then raw else raw.dig(*keychain) end]
32
- end
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 root?
53
- @root
47
+ def weight
48
+ keychain
54
49
  end
55
50
 
56
- def weight
57
- keychain.length
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
@@ -1,3 +1,3 @@
1
1
  module SmartParams
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
data/lib/smart_params.rb CHANGED
@@ -86,7 +86,7 @@ module SmartParams
86
86
 
87
87
  class_methods do
88
88
  def schema(type:, &subfield)
89
- @schema = Field.new(keychain: [], type: type, root: true, &subfield)
89
+ @schema = Field.new(keychain: [], type: type, &subfield)
90
90
  end
91
91
  end
92
92
  end
@@ -87,10 +87,11 @@ RSpec.describe SmartParams do
87
87
  data: {
88
88
  type: "accounts",
89
89
  attributes: {
90
- email: "kurtis@example.com"
90
+ email: "kurtis@example.com",
91
+ y: "y"
91
92
  }
92
93
  },
93
- x: "y"
94
+ x: "x"
94
95
  }
95
96
  end
96
97
 
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.3
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-22 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler