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 +4 -4
- data/README.md +13 -0
- data/lib/parametric/field.rb +1 -1
- data/lib/parametric/policies.rb +10 -0
- data/lib/parametric/version.rb +1 -1
- data/spec/field_spec.rb +18 -0
- 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: aae28a677e19d7f7f3ba7643cd6500f15e148091569b52297fca50505705b4c0
|
4
|
+
data.tar.gz: a5a9a5b21cc043f846afffee551e35e58842cd14fe07a99c6c8661bc0f7ef35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/parametric/field.rb
CHANGED
data/lib/parametric/policies.rb
CHANGED
@@ -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"
|
data/lib/parametric/version.rb
CHANGED
data/spec/field_spec.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2019-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|