dry-validation 0.13.3 → 1.3.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +233 -12
- data/LICENSE +1 -1
- data/README.md +13 -9
- data/config/errors.yml +3 -88
- data/lib/dry-validation.rb +2 -0
- data/lib/dry/validation.rb +47 -28
- data/lib/dry/validation/config.rb +24 -0
- data/lib/dry/validation/constants.rb +43 -0
- data/lib/dry/validation/contract.rb +160 -0
- data/lib/dry/validation/contract/class_interface.rb +223 -0
- data/lib/dry/validation/evaluator.rb +197 -0
- data/lib/dry/validation/extensions/hints.rb +69 -0
- data/lib/dry/validation/extensions/monads.rb +23 -7
- data/lib/dry/validation/extensions/predicates_as_macros.rb +75 -0
- data/lib/dry/validation/failures.rb +58 -0
- data/lib/dry/validation/function.rb +44 -0
- data/lib/dry/validation/macro.rb +38 -0
- data/lib/dry/validation/macros.rb +104 -0
- data/lib/dry/validation/message.rb +79 -79
- data/lib/dry/validation/message_set.rb +108 -88
- data/lib/dry/validation/messages/resolver.rb +79 -0
- data/lib/dry/validation/result.rb +154 -42
- data/lib/dry/validation/rule.rb +129 -0
- data/lib/dry/validation/schema_ext.rb +46 -0
- data/lib/dry/validation/values.rb +94 -0
- data/lib/dry/validation/version.rb +3 -1
- metadata +41 -336
- data/.codeclimate.yml +0 -17
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.travis.yml +0 -29
- data/CONTRIBUTING.md +0 -31
- data/Gemfile +0 -25
- data/Rakefile +0 -22
- data/benchmarks/benchmark_form_invalid.rb +0 -64
- data/benchmarks/benchmark_form_valid.rb +0 -64
- data/benchmarks/benchmark_schema_invalid_huge.rb +0 -52
- data/benchmarks/profile_schema_call_invalid.rb +0 -20
- data/benchmarks/profile_schema_call_valid.rb +0 -20
- data/benchmarks/profile_schema_definition.rb +0 -14
- data/benchmarks/profile_schema_huge_invalid.rb +0 -30
- data/benchmarks/profile_schema_messages_invalid.rb +0 -20
- data/benchmarks/suite.rb +0 -5
- data/dry-validation.gemspec +0 -28
- data/examples/basic.rb +0 -15
- data/examples/each.rb +0 -14
- data/examples/json.rb +0 -12
- data/examples/multiple.rb +0 -27
- data/examples/nested.rb +0 -22
- data/examples/params.rb +0 -11
- data/lib/dry/validation/compat/form.rb +0 -67
- data/lib/dry/validation/deprecations.rb +0 -24
- data/lib/dry/validation/executor.rb +0 -91
- data/lib/dry/validation/extensions.rb +0 -7
- data/lib/dry/validation/extensions/struct.rb +0 -32
- data/lib/dry/validation/input_processor_compiler.rb +0 -137
- data/lib/dry/validation/input_processor_compiler/json.rb +0 -45
- data/lib/dry/validation/input_processor_compiler/params.rb +0 -49
- data/lib/dry/validation/input_processor_compiler/sanitizer.rb +0 -47
- data/lib/dry/validation/message_compiler.rb +0 -188
- data/lib/dry/validation/message_compiler/visitor_opts.rb +0 -37
- data/lib/dry/validation/messages.rb +0 -14
- data/lib/dry/validation/messages/abstract.rb +0 -119
- data/lib/dry/validation/messages/i18n.rb +0 -47
- data/lib/dry/validation/messages/namespaced.rb +0 -39
- data/lib/dry/validation/messages/yaml.rb +0 -61
- data/lib/dry/validation/predicate_registry.rb +0 -115
- data/lib/dry/validation/predicates.rb +0 -19
- data/lib/dry/validation/schema.rb +0 -126
- data/lib/dry/validation/schema/check.rb +0 -37
- data/lib/dry/validation/schema/class_interface.rb +0 -190
- data/lib/dry/validation/schema/deprecated.rb +0 -30
- data/lib/dry/validation/schema/dsl.rb +0 -118
- data/lib/dry/validation/schema/form.rb +0 -9
- data/lib/dry/validation/schema/json.rb +0 -21
- data/lib/dry/validation/schema/key.rb +0 -71
- data/lib/dry/validation/schema/params.rb +0 -22
- data/lib/dry/validation/schema/rule.rb +0 -202
- data/lib/dry/validation/schema/value.rb +0 -211
- data/lib/dry/validation/schema_compiler.rb +0 -81
- data/lib/dry/validation/template.rb +0 -66
- data/lib/dry/validation/type_specs.rb +0 -70
- data/spec/extensions/monads/result_spec.rb +0 -40
- data/spec/extensions/struct/schema_spec.rb +0 -32
- data/spec/fixtures/locales/en.yml +0 -8
- data/spec/fixtures/locales/pl.yml +0 -22
- data/spec/integration/custom_error_messages_spec.rb +0 -54
- data/spec/integration/custom_predicates_spec.rb +0 -228
- data/spec/integration/hints_spec.rb +0 -170
- data/spec/integration/injecting_rules_spec.rb +0 -30
- data/spec/integration/json/defining_base_schema_spec.rb +0 -41
- data/spec/integration/localized_error_messages_spec.rb +0 -72
- data/spec/integration/message_compiler_spec.rb +0 -405
- data/spec/integration/messages/i18n_spec.rb +0 -104
- data/spec/integration/optional_keys_spec.rb +0 -28
- data/spec/integration/params/predicates/array_spec.rb +0 -287
- data/spec/integration/params/predicates/empty_spec.rb +0 -263
- data/spec/integration/params/predicates/eql_spec.rb +0 -327
- data/spec/integration/params/predicates/even_spec.rb +0 -455
- data/spec/integration/params/predicates/excluded_from_spec.rb +0 -455
- data/spec/integration/params/predicates/excludes_spec.rb +0 -391
- data/spec/integration/params/predicates/false_spec.rb +0 -455
- data/spec/integration/params/predicates/filled_spec.rb +0 -467
- data/spec/integration/params/predicates/format_spec.rb +0 -454
- data/spec/integration/params/predicates/gt_spec.rb +0 -519
- data/spec/integration/params/predicates/gteq_spec.rb +0 -519
- data/spec/integration/params/predicates/included_in_spec.rb +0 -455
- data/spec/integration/params/predicates/includes_spec.rb +0 -391
- data/spec/integration/params/predicates/key_spec.rb +0 -67
- data/spec/integration/params/predicates/lt_spec.rb +0 -519
- data/spec/integration/params/predicates/lteq_spec.rb +0 -519
- data/spec/integration/params/predicates/max_size_spec.rb +0 -391
- data/spec/integration/params/predicates/min_size_spec.rb +0 -391
- data/spec/integration/params/predicates/none_spec.rb +0 -265
- data/spec/integration/params/predicates/not_eql_spec.rb +0 -327
- data/spec/integration/params/predicates/odd_spec.rb +0 -455
- data/spec/integration/params/predicates/size/fixed_spec.rb +0 -393
- data/spec/integration/params/predicates/size/range_spec.rb +0 -396
- data/spec/integration/params/predicates/true_spec.rb +0 -455
- data/spec/integration/params/predicates/type_spec.rb +0 -391
- data/spec/integration/result_spec.rb +0 -81
- data/spec/integration/schema/array_schema_spec.rb +0 -59
- data/spec/integration/schema/check_rules_spec.rb +0 -119
- data/spec/integration/schema/check_with_nested_el_spec.rb +0 -37
- data/spec/integration/schema/check_with_nth_el_spec.rb +0 -25
- data/spec/integration/schema/default_settings_spec.rb +0 -11
- data/spec/integration/schema/defining_base_schema_spec.rb +0 -41
- data/spec/integration/schema/dynamic_predicate_args_spec.rb +0 -43
- data/spec/integration/schema/each_with_set_spec.rb +0 -70
- data/spec/integration/schema/extending_dsl_spec.rb +0 -27
- data/spec/integration/schema/form_spec.rb +0 -236
- data/spec/integration/schema/hash_schema_spec.rb +0 -47
- data/spec/integration/schema/inheriting_schema_spec.rb +0 -31
- data/spec/integration/schema/input_processor_spec.rb +0 -46
- data/spec/integration/schema/json/explicit_types_spec.rb +0 -157
- data/spec/integration/schema/json_spec.rb +0 -163
- data/spec/integration/schema/macros/confirmation_spec.rb +0 -35
- data/spec/integration/schema/macros/each_spec.rb +0 -268
- data/spec/integration/schema/macros/filled_spec.rb +0 -87
- data/spec/integration/schema/macros/input_spec.rb +0 -139
- data/spec/integration/schema/macros/maybe_spec.rb +0 -99
- data/spec/integration/schema/macros/rule_spec.rb +0 -75
- data/spec/integration/schema/macros/value_spec.rb +0 -119
- data/spec/integration/schema/macros/when_spec.rb +0 -62
- data/spec/integration/schema/nested_schemas_spec.rb +0 -236
- data/spec/integration/schema/nested_values_spec.rb +0 -46
- data/spec/integration/schema/not_spec.rb +0 -34
- data/spec/integration/schema/numbers_spec.rb +0 -19
- data/spec/integration/schema/option_with_default_spec.rb +0 -64
- data/spec/integration/schema/or_spec.rb +0 -87
- data/spec/integration/schema/params/defining_base_schema_spec.rb +0 -41
- data/spec/integration/schema/params/explicit_types_spec.rb +0 -195
- data/spec/integration/schema/params_spec.rb +0 -234
- data/spec/integration/schema/predicate_verification_spec.rb +0 -9
- data/spec/integration/schema/predicates/array_spec.rb +0 -295
- data/spec/integration/schema/predicates/custom_spec.rb +0 -103
- data/spec/integration/schema/predicates/empty_spec.rb +0 -263
- data/spec/integration/schema/predicates/eql_spec.rb +0 -327
- data/spec/integration/schema/predicates/even_spec.rb +0 -455
- data/spec/integration/schema/predicates/excluded_from/array_spec.rb +0 -459
- data/spec/integration/schema/predicates/excluded_from/range_spec.rb +0 -459
- data/spec/integration/schema/predicates/excludes_spec.rb +0 -391
- data/spec/integration/schema/predicates/filled_spec.rb +0 -467
- data/spec/integration/schema/predicates/format_spec.rb +0 -455
- data/spec/integration/schema/predicates/gt_spec.rb +0 -519
- data/spec/integration/schema/predicates/gteq_spec.rb +0 -519
- data/spec/integration/schema/predicates/hash_spec.rb +0 -69
- data/spec/integration/schema/predicates/included_in/array_spec.rb +0 -459
- data/spec/integration/schema/predicates/included_in/range_spec.rb +0 -459
- data/spec/integration/schema/predicates/includes_spec.rb +0 -391
- data/spec/integration/schema/predicates/key_spec.rb +0 -88
- data/spec/integration/schema/predicates/lt_spec.rb +0 -520
- data/spec/integration/schema/predicates/lteq_spec.rb +0 -519
- data/spec/integration/schema/predicates/max_size_spec.rb +0 -391
- data/spec/integration/schema/predicates/min_size_spec.rb +0 -391
- data/spec/integration/schema/predicates/none_spec.rb +0 -265
- data/spec/integration/schema/predicates/not_eql_spec.rb +0 -391
- data/spec/integration/schema/predicates/odd_spec.rb +0 -455
- data/spec/integration/schema/predicates/size/fixed_spec.rb +0 -398
- data/spec/integration/schema/predicates/size/range_spec.rb +0 -395
- data/spec/integration/schema/predicates/type_spec.rb +0 -413
- data/spec/integration/schema/reusing_schema_spec.rb +0 -33
- data/spec/integration/schema/using_types_spec.rb +0 -135
- data/spec/integration/schema/validate_spec.rb +0 -120
- data/spec/integration/schema/xor_spec.rb +0 -35
- data/spec/integration/schema_builders_spec.rb +0 -17
- data/spec/integration/schema_spec.rb +0 -173
- data/spec/shared/message_compiler.rb +0 -11
- data/spec/shared/predicate_helper.rb +0 -15
- data/spec/shared/rule_compiler.rb +0 -8
- data/spec/spec_helper.rb +0 -62
- data/spec/support/define_struct.rb +0 -25
- data/spec/support/matchers.rb +0 -38
- data/spec/support/mutant.rb +0 -9
- data/spec/support/predicates_integration.rb +0 -7
- data/spec/unit/input_processor_compiler/json_spec.rb +0 -283
- data/spec/unit/input_processor_compiler/params_spec.rb +0 -328
- data/spec/unit/message_compiler/visit_failure_spec.rb +0 -38
- data/spec/unit/message_compiler/visit_spec.rb +0 -16
- data/spec/unit/message_compiler_spec.rb +0 -7
- data/spec/unit/predicate_registry_spec.rb +0 -34
- data/spec/unit/schema/key_spec.rb +0 -38
- data/spec/unit/schema/rule_spec.rb +0 -42
- data/spec/unit/schema/value_spec.rb +0 -131
- data/spec/unit/schema_spec.rb +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f61fe3205cc418d53bd0f2217bdd49a0e49119a69cae87ecf24e76a89567f845
|
|
4
|
+
data.tar.gz: 4ca306db1fd196c3253a78a6376fe0d4c197c5c8d625636bc37038b9caa3278b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0c6a082c4a7077bd428e1bbe2f8ec4677950ea0f073d15cb955568307e2924b75e9d4bfb0f023b65739df7d061569e1aa8a3941968c263d68f4fd3fe12a61d5
|
|
7
|
+
data.tar.gz: 50fa2999ebe80ce40fe244b10bac6cf3644f4dd7e7825913726e8cc2587a901f0d2d164d1c29e17b55f613bd7258dc13d672a5787334f90afc4059d0480312b9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,31 +1,244 @@
|
|
|
1
|
-
#
|
|
1
|
+
# v1.3.1 2019-08-16
|
|
2
|
+
|
|
3
|
+
### Changed
|
|
4
|
+
|
|
5
|
+
* You can now set an external schema without providing a block (alassek)
|
|
6
|
+
|
|
7
|
+
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-validation/compare/v1.3.0...v1.3.1)
|
|
8
|
+
|
|
9
|
+
# v1.3.0 2019-08-14
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
* Support for setting an external schema (that can be extended too) (fixed #574) (@solnic)
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
* Using a hash spec to define rule keys with more than one value is properly handled by rule guard now (fixed #576) (@solnic)
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
* `values` within rules uses `Hash#fetch_values` internally now, which improves performance (@esparta)
|
|
22
|
+
|
|
23
|
+
[Compare v1.2.1...v1.3.0](https://github.com/dry-rb/dry-validation/compare/v1.2.1...v1.3.0)
|
|
24
|
+
|
|
25
|
+
# v1.2.1 2019-07-16
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
* Defining an abstract contract class that has no schema no longer crashes (issue #565) (@solnic)
|
|
30
|
+
* Fixed an issue where `Rule#each` would crash when the value is not an array (issue #567) (@solnic)
|
|
31
|
+
* Fixed an issue where guarding a rule would crash when keys are missing in the input (issue #569) (@solnic)
|
|
32
|
+
* Added missing "pathname" require (issue #570) (@solnic)
|
|
33
|
+
|
|
34
|
+
[Compare v1.2.0...v1.2.1](https://github.com/dry-rb/dry-validation/compare/v1.2.0...v1.2.1)
|
|
35
|
+
|
|
36
|
+
# v1.2.0 2019-07-08
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
* New extension `:predicates_as_macros` (@waiting-for-dev)
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
* Guarding rules for nested keys works correctly (issue #560) (@solnic)
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
* `dry-schema` dependency was bumped to `>= 1.3.1` (@solnic)
|
|
49
|
+
|
|
50
|
+
[Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-validation/compare/v1.1.1...v1.2.0)
|
|
51
|
+
|
|
52
|
+
# v1.1.1 2019-06-24
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
* `Rule#each` works with array values from nested hashes (@mustardnoise)
|
|
57
|
+
|
|
58
|
+
[Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-validation/compare/v1.1.0...v1.1.1)
|
|
59
|
+
|
|
60
|
+
# v1.1.0 2019-06-14
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
|
|
64
|
+
* `key?` method available within rules, that can be used to check if there's a value under the rule's default key (refs #540) (@solnic)
|
|
65
|
+
* `value` supports hash-based path specifications now (refs #547) (@solnic)
|
|
66
|
+
* `value` can read multiple values when the key points to them, ie in case of `rule(geo: [:lat, :lon])` it would return an array with `lat` and `lon` (@solnic)
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
* Passing multiple macro names to `validate` or `each` works correctly (fixed #538 #541) (@jandudulski)
|
|
71
|
+
|
|
72
|
+
[Compare v1.0.0...v1.1.0](https://github.com/dry-rb/dry-validation/compare/v1.0.0...v1.1.0)
|
|
73
|
+
|
|
74
|
+
# v1.0.0 2019-06-10
|
|
75
|
+
|
|
76
|
+
This release is a complete rewrite on top of `dry-schema` that uses contract classes to define schema and validation rules. It's **not backward-compatible**. This release addressed over 150 known issues, including bugs and missing features.
|
|
77
|
+
|
|
78
|
+
See [the list of all addressed issues](https://github.com/dry-rb/dry-validation/issues?utf8=✓&q=is%3Aissue+is%3Aclosed+closed%3A%3E%3D2019-01-01+) as well as issues that were moved to dry-schema and [addressed there](https://github.com/dry-rb/dry-schema/issues?q=is%3Aissue+is%3Aclosed+dry-validation+milestone%3A1.0.0).
|
|
79
|
+
|
|
80
|
+
### :sparkles: Release highlights :sparkles:
|
|
81
|
+
|
|
82
|
+
- New `Dry::Validation::Contract` API for defining contract classes with schemas and validation rules
|
|
83
|
+
- Improved message backends with support for `key` and `base` messages, and arbitrary meta-data (like error codes etc.)
|
|
84
|
+
- Support for defining rules for array elements ie `rule(:items).each { ... }`
|
|
85
|
+
- Support for macros that encapsulate common rule logic
|
|
86
|
+
- Built-in `:acceptance` macro
|
|
87
|
+
|
|
88
|
+
[Compare v0.13.3...v1.0.0](https://github.com/dry-rb/dry-validation/compare/v0.13.3...v1.0.0)
|
|
89
|
+
|
|
90
|
+
# v1.0.0 2019-06-10 (compared to 1.0.0.rc3)
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
|
|
94
|
+
- Support for defining rules for each element of an array via `rule(:items).each { ... }` (solnic)
|
|
95
|
+
- Support for parameterized macros via `rule(:foo).validate(my_macro: :some_option)` (solnic)
|
|
96
|
+
- `values#[]` is now compatible with path specs (symbol, array with keys or dot-notation) (issue #528) (solnic)
|
|
97
|
+
- `value` shortcut for accessing the value found under the first key specified by a rule. ie `rule(:foo) { value }` returns `values[:foo]` (solnic)
|
|
98
|
+
|
|
99
|
+
### Fixed
|
|
100
|
+
|
|
101
|
+
- Contract's `config.locale` option was replaced by `config.messages.default_locale` to avoid conflicts with run-time `:locale` option and/or whatever is set via `I18n` gem (solnic)
|
|
102
|
+
- Macros no longer mutate `Dry::Validation::Contract.macros` when using inheritance (solnic)
|
|
103
|
+
- Missing dependency on `dry-container` was added (solnic)
|
|
104
|
+
|
|
105
|
+
### Changed
|
|
106
|
+
|
|
107
|
+
- `rule` will raise `InvalidKeysError` when specified keys are not defined by the schema (solnic)
|
|
108
|
+
- `Contract.new` will raise `SchemaMissingError` when the class doesn't have schema defined (solnic)
|
|
109
|
+
- Contracts no longer support `:locale` option in the constructor. Use `Result#errors(locale: :pl)` to change locale at run-time (solnic)
|
|
110
|
+
|
|
111
|
+
[Compare v1.0.0.rc3...v1.0.0](https://github.com/dry-rb/dry-validation/compare/v1.0.0.rc3...v1.0.0)
|
|
112
|
+
|
|
113
|
+
# v1.0.0.rc3 2019-05-06
|
|
114
|
+
|
|
115
|
+
### Added
|
|
116
|
+
|
|
117
|
+
* [EXPERIMENTAL] `Validation.register_macro` for registering global macros (solnic)
|
|
118
|
+
* [EXPERIMENTAL] `Contract.register_macro` for registering macros available to specific contract classes (solnic)
|
|
119
|
+
* `Dry::Validation.Contract` shortcut for quickly defining a contract and getting its instance back (solnic)
|
|
120
|
+
* New configuration option `config.locale` for setting the default locale (solnic)
|
|
2
121
|
|
|
3
122
|
### Fixed
|
|
4
123
|
|
|
5
|
-
*
|
|
6
|
-
|
|
124
|
+
* `config/errors.yml` are now bundled with the gem, **`rc2` was broken because of this** (solnic)
|
|
125
|
+
|
|
126
|
+
[Compare v1.0.0.rc2...v1.0.0.rc3](https://github.com/dry-rb/dry-validation/compare/v1.0.0.rc2...v1.0.0.rc3)
|
|
127
|
+
|
|
128
|
+
# v1.0.0.rc2 2019-05-04
|
|
129
|
+
|
|
130
|
+
This was **yanked** on rubygems.org because the bundled gem was missing `config` directory, thus it was not possible to require it. It was fixed in `rc3`.
|
|
131
|
+
|
|
132
|
+
### Added
|
|
133
|
+
|
|
134
|
+
* [EXPERIMENTAL] support for registering macros via `Dry::Validation::Macros.register(:your_macro, &block)` (solnic)
|
|
135
|
+
* [EXPERIMENTAL] `:acceptance` as the first built-in macro (issue #157) (solnic)
|
|
136
|
+
|
|
137
|
+
### Fixed
|
|
138
|
+
|
|
139
|
+
* Passing invalid argument to `failure` will raise a meaningful error instead of crashing (solnic)
|
|
7
140
|
|
|
8
141
|
### Changed
|
|
9
142
|
|
|
10
|
-
*
|
|
143
|
+
* In rule validation blocks, `values` is now an instance of a hash-like `Dry::Validation::Values` class, rather than `Dry::Schema::Result`. This gives more convenient access to data within rules (solnic)
|
|
144
|
+
* Dependency on `dry-schema` was updated to `~> 1.0` (solnic)
|
|
11
145
|
|
|
12
|
-
[Compare
|
|
146
|
+
[Compare v1.0.0.rc1...v1.0.0.rc2](https://github.com/dry-rb/dry-validation/compare/v1.0.0.rc1...v1.0.0.rc2)
|
|
13
147
|
|
|
14
|
-
#
|
|
148
|
+
# v1.0.0.rc1 2019-04-26
|
|
149
|
+
|
|
150
|
+
### Added
|
|
151
|
+
|
|
152
|
+
* `:hints` extension is back (solnic)
|
|
153
|
+
* `Result` objects have access to the context object which is shared between rules (flash-gordon)
|
|
15
154
|
|
|
16
155
|
### Fixed
|
|
17
156
|
|
|
18
|
-
*
|
|
157
|
+
* Multiple hint messages no longer crash message set (flash-gordon)
|
|
158
|
+
* `Contract#inspect` no longer crashes (solnic)
|
|
159
|
+
|
|
160
|
+
### Changed
|
|
161
|
+
|
|
162
|
+
* Dependency on `dry-schema` was bumped to `~> 0.6` - this pulls in `dry-types 1.0.0` and `dry-logic 1.0.0` (solnic)
|
|
163
|
+
* Dependency on `dry-initializer` was bumped to `~> 3.0` (solnic)
|
|
164
|
+
|
|
165
|
+
[Compare v1.0.0.beta2...v1.0.0.rc1](https://github.com/dry-rb/dry-validation/compare/v1.0.0.beta2...v1.0.0.rc1)
|
|
166
|
+
|
|
167
|
+
# v1.0.0.beta2 2019-04-04
|
|
168
|
+
|
|
169
|
+
### Added
|
|
170
|
+
|
|
171
|
+
* Support for arbitrary meta-data in failures, ie:
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
class NewUserContract < Dry::Validation::Contract
|
|
175
|
+
params do
|
|
176
|
+
required(:login).filled(:string)
|
|
177
|
+
end
|
|
19
178
|
|
|
20
|
-
|
|
179
|
+
rule(:login) do
|
|
180
|
+
key.failure(text: 'is taken', code: 123) unless db.unique?(values[:login])
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
```
|
|
21
184
|
|
|
22
|
-
|
|
185
|
+
Now your error hash will include `{ login: [{ text: 'is taken', code: 123 }] }` (solnic + flash-gordon)
|
|
23
186
|
|
|
24
187
|
### Changed
|
|
25
188
|
|
|
26
|
-
|
|
189
|
+
* [BREAKING] `Error` was renamed to `Message` as it is a more generic concept (solnic)
|
|
190
|
+
* [BREAKING] `ErrorSet` was renamed to `MessageSet` for consistency (solnic)
|
|
191
|
+
* [BREAKING] `:monads` extension wraps entire result objects in `Success` or `Failure` (flash-gordon)
|
|
27
192
|
|
|
28
|
-
[Compare
|
|
193
|
+
[Compare v1.0.0.beta1...v1.0.0.beta2](https://github.com/dry-rb/dry-validation/compare/v1.0.0.beta1...v1.0.0.beta2)
|
|
194
|
+
|
|
195
|
+
# v1.0.0.beta1 2019-03-26
|
|
196
|
+
|
|
197
|
+
### Added
|
|
198
|
+
|
|
199
|
+
* New API for setting failures `base.failure` for base errors and `key.failure` for key errors (solnic)
|
|
200
|
+
* Support for `base` errors associated with a key even when child keys have errors too (solnic)
|
|
201
|
+
* Support for `base` errors not associated with any key (solnic)
|
|
202
|
+
* Result objects use `ErrorSet` object now for managing messages (solnic)
|
|
203
|
+
* Nested keys are properly handled when generating messages hash (issue #489) (flash-gordon + solnic)
|
|
204
|
+
* Result objects support `locale` and `full` options now (solnic)
|
|
205
|
+
* Ability to configure `top_namespace` for messages, which will be used for both schema and rule localization (solnic)
|
|
206
|
+
* Rule blocks receive a context object that you can use to share data between rules (solnic)
|
|
207
|
+
|
|
208
|
+
### Changed
|
|
209
|
+
|
|
210
|
+
* [BREAKING] `Result#errors` returns an instance of `ErrorSet` now, it's an enumerable, coerible to a hash (solnic)
|
|
211
|
+
* [BREAKING] `failure` was removed in favor of `key.failure` or `key(:foo).failure` (solnic)
|
|
212
|
+
* [BREAKING] `Result#to_hash` was removed (flash-gordon)
|
|
213
|
+
|
|
214
|
+
[Compare v1.0.0.alpha2...v1.0.0.beta1](https://github.com/dry-rb/dry-validation/compare/v1.0.0.alpha2...v1.0.0.beta1)
|
|
215
|
+
|
|
216
|
+
# v1.0.0.alpha2 2019-03-05
|
|
217
|
+
|
|
218
|
+
First round of bug fixes. Thanks for testing <3!
|
|
219
|
+
|
|
220
|
+
### Fixed
|
|
221
|
+
|
|
222
|
+
* Errors with nested messages are correctly built (flash-gordon)
|
|
223
|
+
* Messages for nested keys are correctly resolved (solnic)
|
|
224
|
+
* A message for a nested key is resolved when it's defined under `errors.rule.%{key}` too, but a message under nested key will override it (solnic)
|
|
225
|
+
|
|
226
|
+
### Changed
|
|
227
|
+
|
|
228
|
+
* When a message template is not found a more meaningful error is raised that includes both rule identifier and key path (solnic)
|
|
229
|
+
|
|
230
|
+
[Compare v1.0.0.alpha1...v1.0.0.alpha2](https://github.com/dry-rb/dry-validation/compare/v1.0.0.alpha1...v1.0.0.alpha2)
|
|
231
|
+
|
|
232
|
+
# v1.0.0.alpha1 2019-03-04
|
|
233
|
+
|
|
234
|
+
Complete rewrite on top of `dry-schema`.
|
|
235
|
+
|
|
236
|
+
### Added
|
|
237
|
+
|
|
238
|
+
* [BREAKING] `Dry::Validation::Contract` as a replacement for validation schemas (solnic)
|
|
239
|
+
* [BREAKING] New `rule` DSL with an improved API for setting error messages (solnic)
|
|
240
|
+
|
|
241
|
+
[Compare v0.13.0...v1.0.0.alpha1](https://github.com/dry-rb/dry-validation/compare/v0.13.0...v1.0.0.alpha1)
|
|
29
242
|
|
|
30
243
|
# v0.13.0 2019-01-29
|
|
31
244
|
|
|
@@ -38,7 +251,15 @@
|
|
|
38
251
|
|
|
39
252
|
- Warning about method redefined (amatsuda)
|
|
40
253
|
|
|
41
|
-
[Compare v0.12.
|
|
254
|
+
[Compare v0.12.3...v0.13.0](https://github.com/dry-rb/dry-validation/compare/v0.12.3...v0.13.0)
|
|
255
|
+
|
|
256
|
+
# v0.12.3 2019-01-29
|
|
257
|
+
|
|
258
|
+
### Changed
|
|
259
|
+
|
|
260
|
+
* [internal] dry-logic was pinned to `~> 0.4.2` (flash-gordon)
|
|
261
|
+
|
|
262
|
+
[Compare v0.12.2...v0.12.3](https://github.com/dry-rb/dry-validation/compare/v0.12.2...v0.12.3)
|
|
42
263
|
|
|
43
264
|
# v0.12.2 2018-08-29
|
|
44
265
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
[gem]: https://rubygems.org/gems/dry-validation
|
|
2
|
-
[travis]: https://travis-ci.
|
|
2
|
+
[travis]: https://travis-ci.com/dry-rb/dry-validation
|
|
3
3
|
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-validation
|
|
4
|
-
[
|
|
4
|
+
[chat]: https://dry-rb.zulipchat.com
|
|
5
5
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-validation
|
|
6
6
|
|
|
7
|
-
# dry-validation [][chat]
|
|
8
8
|
|
|
9
9
|
[][gem]
|
|
10
|
-
[][travis]
|
|
11
11
|
[][codeclimate]
|
|
12
12
|
[][codeclimate]
|
|
13
13
|
[][inchpages]
|
|
14
14
|
|
|
15
|
-
## Status
|
|
16
|
-
|
|
17
|
-
We're working on a new foundation for dry-validation, called dry-schema. You can see progress in [this PR](https://github.com/dry-rb/dry-schema/pull/3). This will result in a partial rewrite for 1.0.0 version. Currently known bugs/issues will be addressed in 1.0.0, **not in 0.x** due to lack of time. More info about 1.0.0 plans can be found [in this thread](https://discourse.dry-rb.org/t/plans-for-dry-validation-dry-schema-a-new-gem/215/3).
|
|
18
|
-
|
|
19
15
|
## Links
|
|
20
16
|
|
|
21
|
-
* [
|
|
17
|
+
* [User documentation](https://dry-rb.org/gems/dry-validation)
|
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-validation)
|
|
22
19
|
* [Guidelines for contributing](CONTRIBUTING.md)
|
|
23
20
|
|
|
21
|
+
## Supported Ruby versions
|
|
22
|
+
|
|
23
|
+
This library officially supports following Ruby versions:
|
|
24
|
+
|
|
25
|
+
* MRI >= `2.4`
|
|
26
|
+
* jruby >= `9.2`
|
|
27
|
+
|
|
24
28
|
## License
|
|
25
29
|
|
|
26
30
|
See `LICENSE` file.
|
data/config/errors.yml
CHANGED
|
@@ -1,89 +1,4 @@
|
|
|
1
1
|
en:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
empty?: "must be empty"
|
|
7
|
-
|
|
8
|
-
excludes?: "must not include %{value}"
|
|
9
|
-
|
|
10
|
-
excluded_from?:
|
|
11
|
-
arg:
|
|
12
|
-
default: "must not be one of: %{list}"
|
|
13
|
-
range: "must not be one of: %{list_left} - %{list_right}"
|
|
14
|
-
exclusion?: "must not be one of: %{list}"
|
|
15
|
-
|
|
16
|
-
eql?: "must be equal to %{left}"
|
|
17
|
-
|
|
18
|
-
not_eql?: "must not be equal to %{left}"
|
|
19
|
-
|
|
20
|
-
filled?: "must be filled"
|
|
21
|
-
|
|
22
|
-
format?: "is in invalid format"
|
|
23
|
-
|
|
24
|
-
number?: "must be a number"
|
|
25
|
-
|
|
26
|
-
odd?: "must be odd"
|
|
27
|
-
|
|
28
|
-
even?: "must be even"
|
|
29
|
-
|
|
30
|
-
gt?: "must be greater than %{num}"
|
|
31
|
-
|
|
32
|
-
gteq?: "must be greater than or equal to %{num}"
|
|
33
|
-
|
|
34
|
-
hash?: "must be a hash"
|
|
35
|
-
|
|
36
|
-
included_in?:
|
|
37
|
-
arg:
|
|
38
|
-
default: "must be one of: %{list}"
|
|
39
|
-
range: "must be one of: %{list_left} - %{list_right}"
|
|
40
|
-
inclusion?: "must be one of: %{list}"
|
|
41
|
-
|
|
42
|
-
includes?: "must include %{value}"
|
|
43
|
-
|
|
44
|
-
bool?: "must be boolean"
|
|
45
|
-
|
|
46
|
-
true?: "must be true"
|
|
47
|
-
|
|
48
|
-
false?: "must be false"
|
|
49
|
-
|
|
50
|
-
int?: "must be an integer"
|
|
51
|
-
|
|
52
|
-
float?: "must be a float"
|
|
53
|
-
|
|
54
|
-
decimal?: "must be a decimal"
|
|
55
|
-
|
|
56
|
-
date?: "must be a date"
|
|
57
|
-
|
|
58
|
-
date_time?: "must be a date time"
|
|
59
|
-
|
|
60
|
-
time?: "must be a time"
|
|
61
|
-
|
|
62
|
-
key?: "is missing"
|
|
63
|
-
|
|
64
|
-
attr?: "is missing"
|
|
65
|
-
|
|
66
|
-
lt?: "must be less than %{num}"
|
|
67
|
-
|
|
68
|
-
lteq?: "must be less than or equal to %{num}"
|
|
69
|
-
|
|
70
|
-
max_size?: "size cannot be greater than %{num}"
|
|
71
|
-
|
|
72
|
-
min_size?: "size cannot be less than %{num}"
|
|
73
|
-
|
|
74
|
-
none?: "cannot be defined"
|
|
75
|
-
|
|
76
|
-
str?: "must be a string"
|
|
77
|
-
|
|
78
|
-
type?: "must be %{type}"
|
|
79
|
-
|
|
80
|
-
size?:
|
|
81
|
-
arg:
|
|
82
|
-
default: "size must be %{size}"
|
|
83
|
-
range: "size must be within %{size_left} - %{size_right}"
|
|
84
|
-
|
|
85
|
-
value:
|
|
86
|
-
string:
|
|
87
|
-
arg:
|
|
88
|
-
default: "length must be %{size}"
|
|
89
|
-
range: "length must be within %{size_left} - %{size_right}"
|
|
2
|
+
dry_validation:
|
|
3
|
+
errors:
|
|
4
|
+
acceptance: "must accept %{key}"
|
data/lib/dry-validation.rb
CHANGED
data/lib/dry/validation.rb
CHANGED
|
@@ -1,43 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
require 'dry/core/constants'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
require 'dry/validation/constants'
|
|
4
|
+
require 'dry/validation/contract'
|
|
5
|
+
require 'dry/validation/macros'
|
|
6
|
+
|
|
7
|
+
# Main namespace
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
4
10
|
module Dry
|
|
11
|
+
# Main library namespace
|
|
12
|
+
#
|
|
13
|
+
# @api public
|
|
5
14
|
module Validation
|
|
6
15
|
extend Dry::Core::Extensions
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
MissingMessageError = Class.new(StandardError)
|
|
10
|
-
InvalidSchemaError = Class.new(StandardError)
|
|
16
|
+
extend Macros::Registrar
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
register_extension(:monads) do
|
|
19
|
+
require 'dry/validation/extensions/monads'
|
|
14
20
|
end
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
register_extension(:hints) do
|
|
23
|
+
require 'dry/validation/extensions/hints'
|
|
24
|
+
end
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
else
|
|
23
|
-
klass.new
|
|
24
|
-
end
|
|
26
|
+
register_extension(:predicates_as_macros) do
|
|
27
|
+
require 'dry/validation/extensions/predicates_as_macros'
|
|
25
28
|
end
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
# Define a contract and build its instance
|
|
31
|
+
#
|
|
32
|
+
# @example
|
|
33
|
+
# my_contract = Dry::Validation.Contract do
|
|
34
|
+
# params do
|
|
35
|
+
# required(:name).filled(:string)
|
|
36
|
+
# end
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# my_contract.call(name: "Jane")
|
|
40
|
+
#
|
|
41
|
+
# @param [Hash] options Contract options
|
|
42
|
+
#
|
|
43
|
+
# @see Contract
|
|
44
|
+
#
|
|
45
|
+
# @return [Contract]
|
|
46
|
+
#
|
|
47
|
+
# @api public
|
|
48
|
+
#
|
|
49
|
+
# rubocop:disable Naming/MethodName
|
|
50
|
+
def self.Contract(options = EMPTY_HASH, &block)
|
|
51
|
+
Contract.build(options, &block)
|
|
30
52
|
end
|
|
53
|
+
# rubocop:enable Naming/MethodName
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
# This is needed by Macros::Registrar
|
|
56
|
+
#
|
|
57
|
+
# @api private
|
|
58
|
+
def self.macros
|
|
59
|
+
Macros
|
|
35
60
|
end
|
|
36
61
|
end
|
|
37
62
|
end
|
|
38
|
-
|
|
39
|
-
require 'dry/validation/schema'
|
|
40
|
-
require 'dry/validation/schema/params'
|
|
41
|
-
require 'dry/validation/schema/json'
|
|
42
|
-
require 'dry/validation/extensions'
|
|
43
|
-
require 'dry/validation/version'
|