dry-validation 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,11 @@ begin
4
4
  require 'byebug'
5
5
  rescue LoadError; end
6
6
 
7
+ if RUBY_ENGINE == "rbx"
8
+ require "codeclimate-test-reporter"
9
+ CodeClimate::TestReporter.start
10
+ end
11
+
7
12
  require 'dry-validation'
8
13
 
9
14
  SPEC_ROOT = Pathname(__dir__)
@@ -0,0 +1,25 @@
1
+ module DefineStruct
2
+ def from_hash(hash = {})
3
+ values = members.map do |attr|
4
+ val = hash[attr]
5
+ val.is_a?(Hash) ? define_struct(*val.keys).from_hash(val) : val
6
+ end
7
+ new(*values)
8
+ end
9
+
10
+ def define_struct(*attrs)
11
+ Struct.new(*attrs) do
12
+ extend DefineStruct
13
+ end
14
+ end
15
+ end
16
+
17
+ def def_struct(*attrs)
18
+ Struct.new(*attrs) do
19
+ extend DefineStruct
20
+ end
21
+ end
22
+
23
+ def struct_from_hash(hash)
24
+ def_struct(*hash.keys).from_hash(hash)
25
+ end
@@ -19,6 +19,22 @@ RSpec.describe HintCompiler, '#call' do
19
19
  ]
20
20
  ]
21
21
  ]
22
+ ],
23
+ ],
24
+ [
25
+ :and, [
26
+ [:attr, [:height, [:predicate, [:attr?, []]]]],
27
+ [
28
+ :or, [
29
+ [:val, [:height, [:predicate, [:none?, []]]]],
30
+ [
31
+ :and, [
32
+ [:val, [:height, [:predicate, [:int?, []]]]],
33
+ [:val, [:height, [:predicate, [:gt?, [180]]]]]
34
+ ]
35
+ ]
36
+ ]
37
+ ]
22
38
  ]
23
39
  ]
24
40
  ]
@@ -26,7 +42,8 @@ RSpec.describe HintCompiler, '#call' do
26
42
 
27
43
  it 'returns hint messages for given rules' do
28
44
  expect(compiler.call).to eql(
29
- age: ['age must be an integer', 'age must be greater than 18']
45
+ age: ['age must be an integer', 'age must be greater than 18'],
46
+ height: ['height must be an integer', 'height must be greater than 180'],
30
47
  )
31
48
  end
32
49
  end
@@ -171,7 +171,7 @@ RSpec.describe Dry::Validation::InputTypeCompiler, '#call' do
171
171
  expect(input_type['bday' => '2012-01-23 11:07']).to eql(bday: Time.new(2012, 1, 23, 11, 7))
172
172
  end
173
173
 
174
- it 'supports bool? => "form.bool"' do
174
+ it 'supports time? => "form.time"' do
175
175
  rule_ast = [
176
176
  [
177
177
  :and,
@@ -187,7 +187,7 @@ RSpec.describe Dry::Validation::InputTypeCompiler, '#call' do
187
187
  expect(input_type['bday' => '2012-01-23 11:07']).to eql(bday: Time.new(2012, 1, 23, 11, 7))
188
188
  end
189
189
 
190
- it 'supports time? => "form.time"' do
190
+ it 'supports bool? => "form.bool"' do
191
191
  rule_ast = [
192
192
  [
193
193
  :and,
@@ -7,25 +7,25 @@ RSpec.describe Schema::Rule do
7
7
 
8
8
  describe '#and' do
9
9
  it 'returns a conjunction' do
10
- expect(left.and(right)).to match_array([:and, [filled, format]])
10
+ expect(left.and(right).to_ary).to match_array([:and, [filled, format]])
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#or' do
15
15
  it 'returns a disjunction' do
16
- expect(left.or(right)).to match_array([:or, [filled, format]])
16
+ expect(left.or(right).to_ary).to match_array([:or, [filled, format]])
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#xor' do
21
21
  it 'returns an exclusive disjunction' do
22
- expect(left.xor(right)).to match_array([:xor, [filled, format]])
22
+ expect(left.xor(right).to_ary).to match_array([:xor, [filled, format]])
23
23
  end
24
24
  end
25
25
 
26
26
  describe '#then' do
27
27
  it 'returns an implication' do
28
- expect(left.then(right)).to match_array([:implication, [filled, format]])
28
+ expect(left.then(right).to_ary).to match_array([:implication, [filled, format]])
29
29
  end
30
30
  end
31
31
  end
@@ -7,7 +7,7 @@ RSpec.describe Schema::Value do
7
7
  value.key?(:method)
8
8
  end
9
9
 
10
- expect(rule).to match_array(
10
+ expect(rule.to_ary).to match_array(
11
11
  [:each, [
12
12
  :payments, [:val, [:payments, [:predicate, [:key?, [:method]]]]]]
13
13
  ]
@@ -20,7 +20,7 @@ RSpec.describe Schema::Value do
20
20
  value.key(:amount) { |amount| amount.float? }
21
21
  end
22
22
 
23
- expect(rule).to match_array(
23
+ expect(rule.to_ary).to match_array(
24
24
  [:each, [
25
25
  :payments, [
26
26
  :set, [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-11 00:00:00.000000000 Z
12
+ date: 2016-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-configurable
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0.1'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.3
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,6 +28,9 @@ dependencies:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0.1'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.3
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: dry-container
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +40,7 @@ dependencies:
34
40
  version: '0.2'
35
41
  - - ">="
36
42
  - !ruby/object:Gem::Version
37
- version: 0.2.6
43
+ version: 0.2.8
38
44
  type: :runtime
39
45
  prerelease: false
40
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +50,7 @@ dependencies:
44
50
  version: '0.2'
45
51
  - - ">="
46
52
  - !ruby/object:Gem::Version
47
- version: 0.2.6
53
+ version: 0.2.8
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: dry-equalizer
50
56
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +72,9 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0.1'
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 0.1.2
69
78
  type: :runtime
70
79
  prerelease: false
71
80
  version_requirements: !ruby/object:Gem::Requirement
@@ -73,6 +82,9 @@ dependencies:
73
82
  - - "~>"
74
83
  - !ruby/object:Gem::Version
75
84
  version: '0.1'
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 0.1.2
76
88
  - !ruby/object:Gem::Dependency
77
89
  name: dry-data
78
90
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +155,7 @@ executables: []
143
155
  extensions: []
144
156
  extra_rdoc_files: []
145
157
  files:
158
+ - ".codeclimate.yml"
146
159
  - ".gitignore"
147
160
  - ".rspec"
148
161
  - ".rubocop.yml"
@@ -173,6 +186,7 @@ files:
173
186
  - lib/dry/validation/messages/yaml.rb
174
187
  - lib/dry/validation/result.rb
175
188
  - lib/dry/validation/schema.rb
189
+ - lib/dry/validation/schema/attr.rb
176
190
  - lib/dry/validation/schema/definition.rb
177
191
  - lib/dry/validation/schema/form.rb
178
192
  - lib/dry/validation/schema/key.rb
@@ -187,18 +201,23 @@ files:
187
201
  - spec/integration/custom_predicates_spec.rb
188
202
  - spec/integration/error_compiler_spec.rb
189
203
  - spec/integration/hints_spec.rb
204
+ - spec/integration/injecting_rules_spec.rb
190
205
  - spec/integration/localized_error_messages_spec.rb
191
206
  - spec/integration/messages/i18n_spec.rb
192
207
  - spec/integration/optional_keys_spec.rb
193
208
  - spec/integration/rule_groups_spec.rb
209
+ - spec/integration/schema/attrs_spec.rb
194
210
  - spec/integration/schema/check_rules_spec.rb
211
+ - spec/integration/schema/default_key_behavior_spec.rb
195
212
  - spec/integration/schema/each_with_set_spec.rb
213
+ - spec/integration/schema/grouped_rules_spec.rb
196
214
  - spec/integration/schema/nested_spec.rb
197
215
  - spec/integration/schema/not_spec.rb
198
216
  - spec/integration/schema/xor_spec.rb
199
217
  - spec/integration/schema_form_spec.rb
200
218
  - spec/integration/schema_spec.rb
201
219
  - spec/spec_helper.rb
220
+ - spec/support/define_struct.rb
202
221
  - spec/unit/error_compiler_spec.rb
203
222
  - spec/unit/hint_compiler_spec.rb
204
223
  - spec/unit/input_type_compiler_spec.rb
@@ -225,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
244
  version: '0'
226
245
  requirements: []
227
246
  rubyforge_project:
228
- rubygems_version: 2.4.5.1
247
+ rubygems_version: 2.5.1
229
248
  signing_key:
230
249
  specification_version: 4
231
250
  summary: A simple validation library
@@ -236,18 +255,23 @@ test_files:
236
255
  - spec/integration/custom_predicates_spec.rb
237
256
  - spec/integration/error_compiler_spec.rb
238
257
  - spec/integration/hints_spec.rb
258
+ - spec/integration/injecting_rules_spec.rb
239
259
  - spec/integration/localized_error_messages_spec.rb
240
260
  - spec/integration/messages/i18n_spec.rb
241
261
  - spec/integration/optional_keys_spec.rb
242
262
  - spec/integration/rule_groups_spec.rb
263
+ - spec/integration/schema/attrs_spec.rb
243
264
  - spec/integration/schema/check_rules_spec.rb
265
+ - spec/integration/schema/default_key_behavior_spec.rb
244
266
  - spec/integration/schema/each_with_set_spec.rb
267
+ - spec/integration/schema/grouped_rules_spec.rb
245
268
  - spec/integration/schema/nested_spec.rb
246
269
  - spec/integration/schema/not_spec.rb
247
270
  - spec/integration/schema/xor_spec.rb
248
271
  - spec/integration/schema_form_spec.rb
249
272
  - spec/integration/schema_spec.rb
250
273
  - spec/spec_helper.rb
274
+ - spec/support/define_struct.rb
251
275
  - spec/unit/error_compiler_spec.rb
252
276
  - spec/unit/hint_compiler_spec.rb
253
277
  - spec/unit/input_type_compiler_spec.rb