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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc68b025c47e3c4d8d4053107aa5d80f935e34b465c1b3f5cf1140aa042305d1
4
- data.tar.gz: 47018cceddad3f64631402abcfb2bfdddb96ef8ba373e51ae08686daecb3e4fa
3
+ metadata.gz: 3b64a30de45ecf284020b1acef587737974cc297895e16d711d3749488af9d38
4
+ data.tar.gz: 45ae399dd90e0d986d34d32f9b240088710698fd00bd88310ae11034b821fce9
5
5
  SHA512:
6
- metadata.gz: c703ec9dcae0d876b994b39933b8f2aa81db05b50a421ce527c409c09c9e75bad21c238e8b9bb25fc29428bd88cf5d21b775ca04547c4ee2acdad8eaf4d52bd8
7
- data.tar.gz: 2e442e6403b10f68f25609873fe47c68bf247e13f716dcb2b960bfc3d4d52e0567794e28f8f1df2970ac28378ed8a391aa21d2cc51952a1e33755199f4b5c8b9
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)
@@ -1,3 +1,3 @@
1
1
  module Parametric
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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.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