parametric 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parametric/block_validator.rb +1 -1
- data/lib/parametric/version.rb +1 -1
- data/spec/custom_block_validator_spec.rb +21 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b64a30de45ecf284020b1acef587737974cc297895e16d711d3749488af9d38
|
4
|
+
data.tar.gz: 45ae399dd90e0d986d34d32f9b240088710698fd00bd88310ae11034b821fce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2ef5e0b0a3b0a7ad7995b0d873b9acb20d8ccce41fd52f64b14ebceeef19c5915d21bfaf561010714cb07bd05933d684c803612557f03337788c3c8fc1c9ac2
|
7
|
+
data.tar.gz: a608ba745a4cd49abd6ee9301ef94398a63a629c20af85f97323d81a88af7bf97e8ce0418c7d436ab87b8ee62c7cad0adca9d38a2c4bcf4f1311b0c12e409dcc
|
@@ -39,7 +39,7 @@ module Parametric
|
|
39
39
|
@validate_block = self.class.validate || ->(*args) { true }
|
40
40
|
@coerce_block = self.class.coerce || ->(v, *_) { v }
|
41
41
|
@eligible_block = self.class.eligible || ->(*args) { true }
|
42
|
-
@meta_data_block = self.class.meta_data || ->() { {} }
|
42
|
+
@meta_data_block = self.class.meta_data || ->(*args) { {} }
|
43
43
|
end
|
44
44
|
|
45
45
|
def eligible?(value, key, payload)
|
data/lib/parametric/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'custom block validator' do
|
4
|
+
Parametric.policy :validate_if do
|
5
|
+
eligible do |options, value, key, payload|
|
6
|
+
options.all? do |key, value|
|
7
|
+
payload[key] == value
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'works if I just define an :eligible block' do
|
13
|
+
schema = Parametric::Schema.new do
|
14
|
+
field(:name).policy(:validate_if, age: 40).present
|
15
|
+
field(:age).type(:integer)
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(schema.resolve(age: 30).errors.any?).to be false
|
19
|
+
expect(schema.resolve(age: 40).errors.any?).to be true # name is missing
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/parametric/struct.rb
|
98
98
|
- lib/parametric/version.rb
|
99
99
|
- parametric.gemspec
|
100
|
+
- spec/custom_block_validator_spec.rb
|
100
101
|
- spec/dsl_spec.rb
|
101
102
|
- spec/expand_spec.rb
|
102
103
|
- spec/field_spec.rb
|
@@ -132,6 +133,7 @@ specification_version: 4
|
|
132
133
|
summary: DSL for declaring allowed parameters with options, regexp patern and default
|
133
134
|
values.
|
134
135
|
test_files:
|
136
|
+
- spec/custom_block_validator_spec.rb
|
135
137
|
- spec/dsl_spec.rb
|
136
138
|
- spec/expand_spec.rb
|
137
139
|
- spec/field_spec.rb
|