parametric 0.2.5 → 0.2.6

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: ab73665f1c6b574e0710689244bf7aad39d37fbd2e6465c8f2185f9bd9421090
4
- data.tar.gz: 829999fb2f7ef34d136b24fc3fd7f7260785bca8cb8fc6dabcae65e3c1f1e14a
3
+ metadata.gz: aae28a677e19d7f7f3ba7643cd6500f15e148091569b52297fca50505705b4c0
4
+ data.tar.gz: a5a9a5b21cc043f846afffee551e35e58842cd14fe07a99c6c8661bc0f7ef35d
5
5
  SHA512:
6
- metadata.gz: 428e567cf0a782f7a424280b79ea10320c7326a95011d4591350b3d96024c67f5e07616fd62103b23f7a98b9e56e970275c668bb285f8192ac7a05950bfd027c
7
- data.tar.gz: 9fd12296245cdcee7a29a7882ae8da866d64ffde1fa065c25136a4a661b30cf97f351bda588b4058b7707c9b2e7688bd0e2b356f2c3438daf8f27f3ecf87a16e
6
+ metadata.gz: e1b3c63ffd393ef506bc82538f03f535f996ca3018a583e8e3f86ccb41ceec375de460b6b5b137011ffa248ed9eef534613a77e069b443cc3da37e2e57b9e5be
7
+ data.tar.gz: 8e3ab7a3d282962b147d44ca822d93b22a98f14111ce860d217d35c0a81d44e621b11c7cf13d471fdec3c5e4f0def860a11edb241f8a98dda48b164ff27c2c80
data/README.md CHANGED
@@ -211,6 +211,19 @@ field(:name).declared.present
211
211
  ```
212
212
 
213
213
  The example above will check that the value is not empty, but only if the key exists. If the key doesn't exist no validations will run.
214
+ Note that any defaults will still be returned.
215
+
216
+ ```ruby
217
+ field(:name).declared.present.default('return this')
218
+ ```
219
+
220
+ ### :declared_no_default
221
+
222
+ Like `:declared`, it stops the policy chain if a key is not in input, but it also skips any default value.
223
+
224
+ ```ruby
225
+ field(:name).policy(:declared_no_default).present
226
+ ```
214
227
 
215
228
  ### :gt
216
229
 
@@ -96,7 +96,7 @@ module Parametric
96
96
  end
97
97
 
98
98
  def has_default?
99
- !!default_block
99
+ !!default_block && !meta_data[:skip_default]
100
100
  end
101
101
 
102
102
  def lookup(key, args)
@@ -44,6 +44,16 @@ module Parametric
44
44
  end
45
45
  end
46
46
 
47
+ Parametric.policy :declared_no_default do
48
+ eligible do |value, key, payload|
49
+ payload.key? key
50
+ end
51
+
52
+ meta_data do
53
+ {skip_default: true}
54
+ end
55
+ end
56
+
47
57
  Parametric.policy :required do
48
58
  message do |*|
49
59
  "is required"
@@ -1,3 +1,3 @@
1
1
  module Parametric
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -266,6 +266,24 @@ describe Parametric::Field do
266
266
  expect(r.value).to eq nil
267
267
  end
268
268
  end
269
+
270
+ it "returns default" do
271
+ resolve(subject.policy(:declared).default('aa'), foo: "").tap do |r|
272
+ expect(r.eligible?).to be true
273
+ no_errors
274
+ expect(r.value).to eq 'aa'
275
+ end
276
+ end
277
+ end
278
+
279
+ describe ':declared_no_default' do
280
+ it "does not return default" do
281
+ resolve(subject.policy(:declared_no_default).default('aa'), lala: "").tap do |r|
282
+ expect(r.eligible?).to be false
283
+ no_errors
284
+ expect(r.value).to eq nil
285
+ end
286
+ end
269
287
  end
270
288
 
271
289
  describe ":noop policy" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parametric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-20 00:00:00.000000000 Z
11
+ date: 2019-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler