dry-validation 0.13.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +233 -12
  3. data/LICENSE +1 -1
  4. data/README.md +13 -9
  5. data/config/errors.yml +3 -88
  6. data/lib/dry-validation.rb +2 -0
  7. data/lib/dry/validation.rb +47 -28
  8. data/lib/dry/validation/config.rb +24 -0
  9. data/lib/dry/validation/constants.rb +43 -0
  10. data/lib/dry/validation/contract.rb +160 -0
  11. data/lib/dry/validation/contract/class_interface.rb +223 -0
  12. data/lib/dry/validation/evaluator.rb +197 -0
  13. data/lib/dry/validation/extensions/hints.rb +69 -0
  14. data/lib/dry/validation/extensions/monads.rb +23 -7
  15. data/lib/dry/validation/extensions/predicates_as_macros.rb +75 -0
  16. data/lib/dry/validation/failures.rb +58 -0
  17. data/lib/dry/validation/function.rb +44 -0
  18. data/lib/dry/validation/macro.rb +38 -0
  19. data/lib/dry/validation/macros.rb +104 -0
  20. data/lib/dry/validation/message.rb +79 -79
  21. data/lib/dry/validation/message_set.rb +108 -88
  22. data/lib/dry/validation/messages/resolver.rb +79 -0
  23. data/lib/dry/validation/result.rb +154 -42
  24. data/lib/dry/validation/rule.rb +129 -0
  25. data/lib/dry/validation/schema_ext.rb +46 -0
  26. data/lib/dry/validation/values.rb +94 -0
  27. data/lib/dry/validation/version.rb +3 -1
  28. metadata +41 -336
  29. data/.codeclimate.yml +0 -17
  30. data/.gitignore +0 -9
  31. data/.rspec +0 -3
  32. data/.travis.yml +0 -29
  33. data/CONTRIBUTING.md +0 -31
  34. data/Gemfile +0 -25
  35. data/Rakefile +0 -22
  36. data/benchmarks/benchmark_form_invalid.rb +0 -64
  37. data/benchmarks/benchmark_form_valid.rb +0 -64
  38. data/benchmarks/benchmark_schema_invalid_huge.rb +0 -52
  39. data/benchmarks/profile_schema_call_invalid.rb +0 -20
  40. data/benchmarks/profile_schema_call_valid.rb +0 -20
  41. data/benchmarks/profile_schema_definition.rb +0 -14
  42. data/benchmarks/profile_schema_huge_invalid.rb +0 -30
  43. data/benchmarks/profile_schema_messages_invalid.rb +0 -20
  44. data/benchmarks/suite.rb +0 -5
  45. data/dry-validation.gemspec +0 -28
  46. data/examples/basic.rb +0 -15
  47. data/examples/each.rb +0 -14
  48. data/examples/json.rb +0 -12
  49. data/examples/multiple.rb +0 -27
  50. data/examples/nested.rb +0 -22
  51. data/examples/params.rb +0 -11
  52. data/lib/dry/validation/compat/form.rb +0 -67
  53. data/lib/dry/validation/deprecations.rb +0 -24
  54. data/lib/dry/validation/executor.rb +0 -91
  55. data/lib/dry/validation/extensions.rb +0 -7
  56. data/lib/dry/validation/extensions/struct.rb +0 -32
  57. data/lib/dry/validation/input_processor_compiler.rb +0 -137
  58. data/lib/dry/validation/input_processor_compiler/json.rb +0 -45
  59. data/lib/dry/validation/input_processor_compiler/params.rb +0 -49
  60. data/lib/dry/validation/input_processor_compiler/sanitizer.rb +0 -47
  61. data/lib/dry/validation/message_compiler.rb +0 -188
  62. data/lib/dry/validation/message_compiler/visitor_opts.rb +0 -37
  63. data/lib/dry/validation/messages.rb +0 -14
  64. data/lib/dry/validation/messages/abstract.rb +0 -119
  65. data/lib/dry/validation/messages/i18n.rb +0 -47
  66. data/lib/dry/validation/messages/namespaced.rb +0 -39
  67. data/lib/dry/validation/messages/yaml.rb +0 -61
  68. data/lib/dry/validation/predicate_registry.rb +0 -115
  69. data/lib/dry/validation/predicates.rb +0 -19
  70. data/lib/dry/validation/schema.rb +0 -126
  71. data/lib/dry/validation/schema/check.rb +0 -37
  72. data/lib/dry/validation/schema/class_interface.rb +0 -190
  73. data/lib/dry/validation/schema/deprecated.rb +0 -30
  74. data/lib/dry/validation/schema/dsl.rb +0 -118
  75. data/lib/dry/validation/schema/form.rb +0 -9
  76. data/lib/dry/validation/schema/json.rb +0 -21
  77. data/lib/dry/validation/schema/key.rb +0 -71
  78. data/lib/dry/validation/schema/params.rb +0 -22
  79. data/lib/dry/validation/schema/rule.rb +0 -202
  80. data/lib/dry/validation/schema/value.rb +0 -211
  81. data/lib/dry/validation/schema_compiler.rb +0 -81
  82. data/lib/dry/validation/template.rb +0 -66
  83. data/lib/dry/validation/type_specs.rb +0 -70
  84. data/spec/extensions/monads/result_spec.rb +0 -40
  85. data/spec/extensions/struct/schema_spec.rb +0 -32
  86. data/spec/fixtures/locales/en.yml +0 -8
  87. data/spec/fixtures/locales/pl.yml +0 -22
  88. data/spec/integration/custom_error_messages_spec.rb +0 -54
  89. data/spec/integration/custom_predicates_spec.rb +0 -228
  90. data/spec/integration/hints_spec.rb +0 -170
  91. data/spec/integration/injecting_rules_spec.rb +0 -30
  92. data/spec/integration/json/defining_base_schema_spec.rb +0 -41
  93. data/spec/integration/localized_error_messages_spec.rb +0 -72
  94. data/spec/integration/message_compiler_spec.rb +0 -405
  95. data/spec/integration/messages/i18n_spec.rb +0 -104
  96. data/spec/integration/optional_keys_spec.rb +0 -28
  97. data/spec/integration/params/predicates/array_spec.rb +0 -287
  98. data/spec/integration/params/predicates/empty_spec.rb +0 -263
  99. data/spec/integration/params/predicates/eql_spec.rb +0 -327
  100. data/spec/integration/params/predicates/even_spec.rb +0 -455
  101. data/spec/integration/params/predicates/excluded_from_spec.rb +0 -455
  102. data/spec/integration/params/predicates/excludes_spec.rb +0 -391
  103. data/spec/integration/params/predicates/false_spec.rb +0 -455
  104. data/spec/integration/params/predicates/filled_spec.rb +0 -467
  105. data/spec/integration/params/predicates/format_spec.rb +0 -454
  106. data/spec/integration/params/predicates/gt_spec.rb +0 -519
  107. data/spec/integration/params/predicates/gteq_spec.rb +0 -519
  108. data/spec/integration/params/predicates/included_in_spec.rb +0 -455
  109. data/spec/integration/params/predicates/includes_spec.rb +0 -391
  110. data/spec/integration/params/predicates/key_spec.rb +0 -67
  111. data/spec/integration/params/predicates/lt_spec.rb +0 -519
  112. data/spec/integration/params/predicates/lteq_spec.rb +0 -519
  113. data/spec/integration/params/predicates/max_size_spec.rb +0 -391
  114. data/spec/integration/params/predicates/min_size_spec.rb +0 -391
  115. data/spec/integration/params/predicates/none_spec.rb +0 -265
  116. data/spec/integration/params/predicates/not_eql_spec.rb +0 -327
  117. data/spec/integration/params/predicates/odd_spec.rb +0 -455
  118. data/spec/integration/params/predicates/size/fixed_spec.rb +0 -393
  119. data/spec/integration/params/predicates/size/range_spec.rb +0 -396
  120. data/spec/integration/params/predicates/true_spec.rb +0 -455
  121. data/spec/integration/params/predicates/type_spec.rb +0 -391
  122. data/spec/integration/result_spec.rb +0 -81
  123. data/spec/integration/schema/array_schema_spec.rb +0 -59
  124. data/spec/integration/schema/check_rules_spec.rb +0 -119
  125. data/spec/integration/schema/check_with_nested_el_spec.rb +0 -37
  126. data/spec/integration/schema/check_with_nth_el_spec.rb +0 -25
  127. data/spec/integration/schema/default_settings_spec.rb +0 -11
  128. data/spec/integration/schema/defining_base_schema_spec.rb +0 -41
  129. data/spec/integration/schema/dynamic_predicate_args_spec.rb +0 -43
  130. data/spec/integration/schema/each_with_set_spec.rb +0 -70
  131. data/spec/integration/schema/extending_dsl_spec.rb +0 -27
  132. data/spec/integration/schema/form_spec.rb +0 -236
  133. data/spec/integration/schema/hash_schema_spec.rb +0 -47
  134. data/spec/integration/schema/inheriting_schema_spec.rb +0 -31
  135. data/spec/integration/schema/input_processor_spec.rb +0 -46
  136. data/spec/integration/schema/json/explicit_types_spec.rb +0 -157
  137. data/spec/integration/schema/json_spec.rb +0 -163
  138. data/spec/integration/schema/macros/confirmation_spec.rb +0 -35
  139. data/spec/integration/schema/macros/each_spec.rb +0 -268
  140. data/spec/integration/schema/macros/filled_spec.rb +0 -87
  141. data/spec/integration/schema/macros/input_spec.rb +0 -139
  142. data/spec/integration/schema/macros/maybe_spec.rb +0 -99
  143. data/spec/integration/schema/macros/rule_spec.rb +0 -75
  144. data/spec/integration/schema/macros/value_spec.rb +0 -119
  145. data/spec/integration/schema/macros/when_spec.rb +0 -62
  146. data/spec/integration/schema/nested_schemas_spec.rb +0 -236
  147. data/spec/integration/schema/nested_values_spec.rb +0 -46
  148. data/spec/integration/schema/not_spec.rb +0 -34
  149. data/spec/integration/schema/numbers_spec.rb +0 -19
  150. data/spec/integration/schema/option_with_default_spec.rb +0 -64
  151. data/spec/integration/schema/or_spec.rb +0 -87
  152. data/spec/integration/schema/params/defining_base_schema_spec.rb +0 -41
  153. data/spec/integration/schema/params/explicit_types_spec.rb +0 -195
  154. data/spec/integration/schema/params_spec.rb +0 -234
  155. data/spec/integration/schema/predicate_verification_spec.rb +0 -9
  156. data/spec/integration/schema/predicates/array_spec.rb +0 -295
  157. data/spec/integration/schema/predicates/custom_spec.rb +0 -103
  158. data/spec/integration/schema/predicates/empty_spec.rb +0 -263
  159. data/spec/integration/schema/predicates/eql_spec.rb +0 -327
  160. data/spec/integration/schema/predicates/even_spec.rb +0 -455
  161. data/spec/integration/schema/predicates/excluded_from/array_spec.rb +0 -459
  162. data/spec/integration/schema/predicates/excluded_from/range_spec.rb +0 -459
  163. data/spec/integration/schema/predicates/excludes_spec.rb +0 -391
  164. data/spec/integration/schema/predicates/filled_spec.rb +0 -467
  165. data/spec/integration/schema/predicates/format_spec.rb +0 -455
  166. data/spec/integration/schema/predicates/gt_spec.rb +0 -519
  167. data/spec/integration/schema/predicates/gteq_spec.rb +0 -519
  168. data/spec/integration/schema/predicates/hash_spec.rb +0 -69
  169. data/spec/integration/schema/predicates/included_in/array_spec.rb +0 -459
  170. data/spec/integration/schema/predicates/included_in/range_spec.rb +0 -459
  171. data/spec/integration/schema/predicates/includes_spec.rb +0 -391
  172. data/spec/integration/schema/predicates/key_spec.rb +0 -88
  173. data/spec/integration/schema/predicates/lt_spec.rb +0 -520
  174. data/spec/integration/schema/predicates/lteq_spec.rb +0 -519
  175. data/spec/integration/schema/predicates/max_size_spec.rb +0 -391
  176. data/spec/integration/schema/predicates/min_size_spec.rb +0 -391
  177. data/spec/integration/schema/predicates/none_spec.rb +0 -265
  178. data/spec/integration/schema/predicates/not_eql_spec.rb +0 -391
  179. data/spec/integration/schema/predicates/odd_spec.rb +0 -455
  180. data/spec/integration/schema/predicates/size/fixed_spec.rb +0 -398
  181. data/spec/integration/schema/predicates/size/range_spec.rb +0 -395
  182. data/spec/integration/schema/predicates/type_spec.rb +0 -413
  183. data/spec/integration/schema/reusing_schema_spec.rb +0 -33
  184. data/spec/integration/schema/using_types_spec.rb +0 -135
  185. data/spec/integration/schema/validate_spec.rb +0 -120
  186. data/spec/integration/schema/xor_spec.rb +0 -35
  187. data/spec/integration/schema_builders_spec.rb +0 -17
  188. data/spec/integration/schema_spec.rb +0 -173
  189. data/spec/shared/message_compiler.rb +0 -11
  190. data/spec/shared/predicate_helper.rb +0 -15
  191. data/spec/shared/rule_compiler.rb +0 -8
  192. data/spec/spec_helper.rb +0 -62
  193. data/spec/support/define_struct.rb +0 -25
  194. data/spec/support/matchers.rb +0 -38
  195. data/spec/support/mutant.rb +0 -9
  196. data/spec/support/predicates_integration.rb +0 -7
  197. data/spec/unit/input_processor_compiler/json_spec.rb +0 -283
  198. data/spec/unit/input_processor_compiler/params_spec.rb +0 -328
  199. data/spec/unit/message_compiler/visit_failure_spec.rb +0 -38
  200. data/spec/unit/message_compiler/visit_spec.rb +0 -16
  201. data/spec/unit/message_compiler_spec.rb +0 -7
  202. data/spec/unit/predicate_registry_spec.rb +0 -34
  203. data/spec/unit/schema/key_spec.rb +0 -38
  204. data/spec/unit/schema/rule_spec.rb +0 -42
  205. data/spec/unit/schema/value_spec.rb +0 -131
  206. data/spec/unit/schema_spec.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d569600e476b1c0830184bea7e9393f333693e11c1a9d8b074e2b2329deeba7a
4
- data.tar.gz: 4811db9bc4e1cc3f398df8717333683355779116a72314532b10bc2d49a87333
3
+ metadata.gz: f61fe3205cc418d53bd0f2217bdd49a0e49119a69cae87ecf24e76a89567f845
4
+ data.tar.gz: 4ca306db1fd196c3253a78a6376fe0d4c197c5c8d625636bc37038b9caa3278b
5
5
  SHA512:
6
- metadata.gz: c497db70c2bf78e3355c685176361b06357ee9d9f17a2c867127d4d575865f0e6cb1f5bafae4b595e1db3af8748fc6122e6522177a152e17e8e6119006591b3c
7
- data.tar.gz: 2b93c44b453e47f6a68ec05bedaec9d2f48d001a6dc9d0f62f2f2d7b70de5f8c1a7130bfc33c558fff1129fceb69d37f33f341d38c96549570a684d7279d24b0
6
+ metadata.gz: d0c6a082c4a7077bd428e1bbe2f8ec4677950ea0f073d15cb955568307e2924b75e9d4bfb0f023b65739df7d061569e1aa8a3941968c263d68f4fd3fe12a61d5
7
+ data.tar.gz: 50fa2999ebe80ce40fe244b10bac6cf3644f4dd7e7825913726e8cc2587a901f0d2d164d1c29e17b55f613bd7258dc13d672a5787334f90afc4059d0480312b9
@@ -1,31 +1,244 @@
1
- # v0.13.3 2019-05-21
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
- * Fixed regression with caching templates that rely on predicate arguments (solnic)
6
- * Removed ugly workaround for template evaluation with extra tokens (solnic)
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
- * [internal] `Messages::Abstract#call` returns a `Template` object now, this was backported from dry-schema (solnic)
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 v0.13.2...v0.13.3](https://github.com/dry-rb/dry-validation/compare/v0.13.2...v0.13.3)
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
- # v0.13.2 2019-05-12
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
- * Caching message templates uses restricted set of known keys to calculate cache keys (solnic)
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
- [Compare v0.13.1...v0.13.2](https://github.com/dry-rb/dry-validation/compare/v0.13.1...v0.13.2)
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
- # v0.13.1 2019-03-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
- - `dry-types` was locked to `~> 0.14.0` (flash-gordon)
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 v0.13.0...v0.13.1](https://github.com/dry-rb/dry-validation/compare/v0.13.0...v0.13.1)
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.2...v0.13.0](https://github.com/dry-rb/dry-validation/compare/v0.12.2...v0.13.0)
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Dryrb Team
3
+ Copyright (c) 2015-2019 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,26 +1,30 @@
1
1
  [gem]: https://rubygems.org/gems/dry-validation
2
- [travis]: https://travis-ci.org/dry-rb/dry-validation
2
+ [travis]: https://travis-ci.com/dry-rb/dry-validation
3
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-validation
4
- [coveralls]: https://coveralls.io/r/dry-rb/dry-validation
4
+ [chat]: https://dry-rb.zulipchat.com
5
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-validation
6
6
 
7
- # dry-validation [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
7
+ # dry-validation [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/dry-validation.svg)][gem]
10
- [![Build Status](https://travis-ci.org/dry-rb/dry-validation.svg?branch=master)][travis]
10
+ [![Build Status](https://travis-ci.com/dry-rb/dry-validation.svg?branch=master)][travis]
11
11
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-validation/badges/gpa.svg)][codeclimate]
12
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-validation/badges/coverage.svg)][codeclimate]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=master)][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
- * [Documentation](http://dry-rb.org/gems/dry-validation)
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.
@@ -1,89 +1,4 @@
1
1
  en:
2
- errors:
3
- or: "or"
4
- array?: "must be an array"
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}"
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/validation'
@@ -1,43 +1,62 @@
1
- require 'dry/core/extensions'
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
- include Dry::Core::Constants
8
-
9
- MissingMessageError = Class.new(StandardError)
10
- InvalidSchemaError = Class.new(StandardError)
16
+ extend Macros::Registrar
11
17
 
12
- def self.messages_paths
13
- Messages::Abstract.config.paths
18
+ register_extension(:monads) do
19
+ require 'dry/validation/extensions/monads'
14
20
  end
15
21
 
16
- def self.Schema(base = Schema, **options, &block)
17
- schema_class = Class.new(base.is_a?(Schema) ? base.class : base)
18
- klass = schema_class.define(options.merge(schema_class: schema_class), &block)
22
+ register_extension(:hints) do
23
+ require 'dry/validation/extensions/hints'
24
+ end
19
25
 
20
- if options[:build] == false
21
- klass
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
- def self.Params(base = nil, **options, &block)
28
- klass = base ? Schema::Params.configure(Class.new(base)) : Schema::Params
29
- Validation.Schema(klass, options, &block)
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
- def self.JSON(base = Schema::JSON, **options, &block)
33
- klass = base ? Schema::JSON.configure(Class.new(base)) : Schema::JSON
34
- Validation.Schema(klass, options, &block)
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'