dry-schema 0.1.0 → 1.0.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +166 -0
  3. data/LICENSE +1 -1
  4. data/README.md +13 -4
  5. data/config/errors.yml +59 -54
  6. data/lib/dry/schema/compiler.rb +24 -0
  7. data/lib/dry/schema/config.rb +23 -27
  8. data/lib/dry/schema/constants.rb +27 -3
  9. data/lib/dry/schema/dsl.rb +36 -49
  10. data/lib/dry/schema/extensions/hints/compiler_methods.rb +19 -0
  11. data/lib/dry/schema/extensions/hints/message_compiler_methods.rb +84 -0
  12. data/lib/dry/schema/extensions/hints/message_set_methods.rb +44 -0
  13. data/lib/dry/schema/extensions/hints/result_methods.rb +47 -0
  14. data/lib/dry/schema/extensions/hints.rb +56 -0
  15. data/lib/dry/schema/extensions/monads.rb +15 -4
  16. data/lib/dry/schema/extensions.rb +6 -0
  17. data/lib/dry/schema/json.rb +4 -2
  18. data/lib/dry/schema/key.rb +8 -10
  19. data/lib/dry/schema/key_coercer.rb +6 -2
  20. data/lib/dry/schema/key_map.rb +5 -4
  21. data/lib/dry/schema/macros/array.rb +39 -0
  22. data/lib/dry/schema/macros/core.rb +2 -0
  23. data/lib/dry/schema/macros/dsl.rb +149 -4
  24. data/lib/dry/schema/macros/each.rb +12 -1
  25. data/lib/dry/schema/macros/filled.rb +14 -7
  26. data/lib/dry/schema/macros/hash.rb +6 -32
  27. data/lib/dry/schema/macros/key.rb +38 -60
  28. data/lib/dry/schema/macros/maybe.rb +5 -3
  29. data/lib/dry/schema/macros/optional.rb +8 -1
  30. data/lib/dry/schema/macros/required.rb +3 -1
  31. data/lib/dry/schema/macros/schema.rb +46 -0
  32. data/lib/dry/schema/macros/value.rb +18 -2
  33. data/lib/dry/schema/macros.rb +4 -0
  34. data/lib/dry/schema/message/or.rb +54 -0
  35. data/lib/dry/schema/message.rb +56 -72
  36. data/lib/dry/schema/message_compiler/visitor_opts.rb +28 -1
  37. data/lib/dry/schema/message_compiler.rb +85 -74
  38. data/lib/dry/schema/message_set.rb +82 -50
  39. data/lib/dry/schema/messages/abstract.rb +84 -44
  40. data/lib/dry/schema/messages/i18n.rb +45 -9
  41. data/lib/dry/schema/messages/namespaced.rb +22 -5
  42. data/lib/dry/schema/messages/template.rb +68 -0
  43. data/lib/dry/schema/messages/yaml.rb +76 -22
  44. data/lib/dry/schema/messages.rb +19 -24
  45. data/lib/dry/schema/namespaced_rule.rb +37 -0
  46. data/lib/dry/schema/params.rb +4 -2
  47. data/lib/dry/schema/path.rb +102 -0
  48. data/lib/dry/schema/predicate.rb +15 -0
  49. data/lib/dry/schema/predicate_inferrer.rb +116 -23
  50. data/lib/dry/schema/predicate_registry.rb +2 -0
  51. data/lib/dry/schema/processor.rb +70 -39
  52. data/lib/dry/schema/result.rb +16 -31
  53. data/lib/dry/schema/rule_applier.rb +10 -3
  54. data/lib/dry/schema/trace.rb +16 -3
  55. data/lib/dry/schema/type_registry.rb +5 -3
  56. data/lib/dry/schema/types.rb +3 -1
  57. data/lib/dry/schema/value_coercer.rb +10 -4
  58. data/lib/dry/schema/version.rb +3 -1
  59. data/lib/dry/schema.rb +39 -13
  60. data/lib/dry-schema.rb +2 -0
  61. metadata +43 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b804e7069cd7d8764f82ce208e38768fa9975e6d1460e1e44917d5c0eaeee911
4
- data.tar.gz: 6814f96c49db2634895c20faf7b331feccbdcdcbc83ff89292f655acd6c0adfc
3
+ metadata.gz: 63100127599f36457192bd183784388f1ca2328c0bd91f4e4d2adb2498b57bb2
4
+ data.tar.gz: 82c6cad8a1bda4c89723a2ccccce7eab8bb56c9e90b0ce385cc4d632993be90c
5
5
  SHA512:
6
- metadata.gz: 80d4cc2626025ef517e48bba83026c1bba7ef5797fa25e2543589ed503ec9d7142e799ed9713d4452b7a1f1b2d2988b4c6aeb3172230ec6fd4987d58c8621775
7
- data.tar.gz: f35d2b94570ec416b6fcb0457a4e685f37ff3a265a011a4016af611307e2d8d1b8b03dc9e4b59a63b5f2cf55aacf8ceabac0a5d689e73f14e4aaa5cef96e1fa4
6
+ metadata.gz: dbef0b527a8e4742b3845d8bebf45b88d960fa969956599f6504ce785fb9d2b7461ad8cc94e2e4b238956dc79641007d54be3b435f73551f2219f01db8b3f60d
7
+ data.tar.gz: c01c98b4600c7fcec9efa3f38f0cd6a27b86191804a7502b80da81d564282cb581ac5bc69c5c006cebb4826d0f7d6653230612a80f530a301494d1fe5af01203
data/CHANGELOG.md CHANGED
@@ -1,3 +1,169 @@
1
+ # 1.0.0 2019-05-03
2
+
3
+ ### Changed
4
+
5
+ * [BREAKING] `Result#to_hash` was removed (solnic)
6
+
7
+ ### Fixed
8
+
9
+ * Setting `:any` as the type spec no longer crashes (solnic)
10
+ * `Result#error?` handles paths to array elements correctly (solnic)
11
+
12
+ [Compare v0.6.0...v1.0.0](https://github.com/dry-rb/dry-schema/compare/v0.6.0...v1.0.0)
13
+
14
+ # 0.6.0 2019-04-24
15
+
16
+ ### Changed
17
+
18
+ * Dependency on `dry-types` was bumped to `~> 1.0` (solnic)
19
+ * Dependency on `dry-logic` was bumped to `~> 1.0` (solnic)
20
+ * Dependency on `dry-initializer` was bumped to `~> 3.0` (solnic)
21
+
22
+ [Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-schema/compare/v0.5.1...v0.6.0)
23
+
24
+ # 0.5.1 2019-04-17
25
+
26
+ ### Fixed
27
+
28
+ * Key map no longer crashes on unexpected input (issue #118) (solnic)
29
+
30
+ [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-schema/compare/v0.5.0...v0.5.1)
31
+
32
+ # 0.5.0 2019-04-04
33
+
34
+ ### Added
35
+
36
+ * Support for arbitrary meta-data in messages, ie:
37
+
38
+ ```yaml
39
+ en:
40
+ dry_schema:
41
+ errors:
42
+ filled?:
43
+ text: "cannot be blank"
44
+ code: 123
45
+ ```
46
+
47
+ Now your error hash will include `{ foo: [{ text: 'cannot be blank', code: 123 }] }` (solnic + flash-gordon)
48
+
49
+ * Support for type specs in `array` macro, ie `required(:tags).array(:integer)` (solnic)
50
+ * Support for type specs in `each` macro, ie `required(:tags).each(:integer)` (solnic)
51
+ * Shortcut for defining an array with hash as its member, ie:
52
+
53
+ ```ruby
54
+ Dry::Schema.Params do
55
+ required(:tags).array(:hash) do
56
+ required(:name).filled(:string)
57
+ end
58
+ end
59
+ ```
60
+
61
+ ### Fixed
62
+
63
+ * Inferring predicates doesn't crash when `Any` type is used (flash-gordon)
64
+ * Inferring type specs when type is already set works correctly (solnic)
65
+
66
+ ### Changed
67
+
68
+ * [BREAKING] `:monads` extension wraps entire result objects in `Success` or `Failure` (flash-gordon)
69
+ * When `:hints` are disabled, result AST will not include hint nodes (solnic)
70
+
71
+ [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-schema/compare/v0.4.0...v0.5.0)
72
+
73
+ # 0.4.0 2019-03-26
74
+
75
+ ### Added
76
+
77
+ * Schemas are now compatible with procs via `#to_proc` (issue #53) (solnic)
78
+ * Support for configuring `top_namespace` for localized messages (solnic)
79
+ * Support for configuring more than one load path for localized messages (solnic)
80
+ * Support for inferring predicates from arbitrary types (issue #101) (solnic)
81
+
82
+ ### Fixed
83
+
84
+ * Handling of messages for `optional` keys without value rules works correctly (issue #87) (solnic)
85
+ * Message structure for `optional` keys with an array of hashes no longer duplicates keys (issue #89) (solnic)
86
+ * Inferring `:date_time?` predicate works correctly with `DateTime` types (issue #97) (solnic)
87
+
88
+ ### Changed
89
+
90
+ * [BREAKING] Updated to work with `dry-types 0.15.0` (flash-gordon)
91
+ * [BREAKING] `Result#{errors,messages,hints}` returns `MessageSet` object now which is an enumerable coercible to a hash (solnic)
92
+ * [BREAKING] `Messages` backend classes no longer use global configuration (solnic)
93
+ * [BREAKING] Passing a non-symbol key name in the DSL will raise `ArgumentError` (issue #29) (solnic)
94
+ * [BREAKING] Configuration for message backends is now nested under `messages` key with following settings:
95
+ * `messages.backend` - previously `messages`
96
+ * `messages.load_paths` - previously `messages_path`
97
+ * `messages.namespace` - previously `namespace`
98
+ * `messages.top_namespace` - **new setting** see above
99
+ * [BREAKING] `Messages::I18n` uses `I18.store_translations` instead of messing with `I18n.load_path` (solnic)
100
+ * Schemas (`Params` and `JSON`) have nicer inspect (solnic)
101
+
102
+ [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-schema/compare/v0.3.0...v0.4.0)
103
+
104
+ # 0.3.0 2018-03-04
105
+
106
+ ### Fixed
107
+
108
+ * Configuration is properly inherited from a parent schema (skryukov)
109
+ * `Result#error?` returns `true` when a preceding key has errors (solnic)
110
+ * Predicate inferrer no longer chokes on sum, constructor and enum types (solnic)
111
+ * Predicate inferrer infers `:bool?` from boolean types (solnic)
112
+ * Block-based definitions using `array` works correctly (solnic)
113
+ * Using a disjunction with `array` and `hash` produces correct errors when element validation for array failed (solnic)
114
+
115
+ ### Changed
116
+
117
+ * Required ruby version was removed from gemspec for people who are stuck on MRI 2.3.x (solnic)
118
+
119
+ [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-schema/compare/v0.2.0...v0.3.0)
120
+
121
+ # 0.2.0 2019-02-26
122
+
123
+ ### Added
124
+
125
+ * New `hash` macro which prepends `hash?` type-check and allows nested schema definition (solnic)
126
+ * New `array` macro which works like `each` but prepends `array?` type-check (solnic)
127
+
128
+ ### Fixed
129
+
130
+ * Rule name translation works correctly with I18n (issue #52) (solnic)
131
+ * Rule name translation works correctly with namespaced messages (both I18n and plain YAML) (issue #57) (solnic)
132
+ * Error messages under namespaces are correctly resolved for overridden names (issue #53) (solnic)
133
+ * Namespaced error messages work correctly when schemas are reused within other schemas (issue #49) (solnic)
134
+ * Child schema can override inherited rules now (issue #66) (skryukov)
135
+ * Hints are correctly generated for disjunction that use type-check predicates (issue #24) (solnic)
136
+ * Hints are correctly generated for nested schemas (issue #26) (solnic)
137
+ * `filled` macro respects inferred type-check predicates and puts them in front (solnic)
138
+ * Value coercion works correctly with re-usable nested schemas (issue #25) (solnic)
139
+
140
+ ### Changed
141
+
142
+ * [BREAKING] **Messages are now configured under `dry_schema` namespace by default** (issue #38) (solnic)
143
+ * [BREAKING] Hints are now an optional feature provided by `:hints` extension, to load it do `Dry::Schema.load_extensions(:hints)` (solnic)
144
+ * [BREAKING] Hints generation was improved in general, output of `Result#messages` and `Result#hints` changed in some cases (solnic)
145
+ * [BREAKING] `schema` macro no longer prepends `hash?` check, for this behavior use the new `hash` macro (see #31) (solnic)
146
+ * [BREAKING] Support for MRI < 2.4 was dropped (solnic)
147
+
148
+ [Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-schema/compare/v0.1.1...v0.2.0)
149
+
150
+ # 0.1.1 2019-02-17
151
+
152
+ ### Added
153
+
154
+ - `Result#error?` supports checking nested errors too ie`result.error?('user.address')` (solnic)
155
+
156
+ ### Fixed
157
+
158
+ - Fix issues with templates and invalid tokens (issue #27) (solnic)
159
+ - Fix Ruby warnings (flash-gordon)
160
+
161
+ ### Internal
162
+
163
+ - Key and value coercers are now equalizable (flash-gordon)
164
+
165
+ [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-schema/compare/v0.1.0...v0.1.1)
166
+
1
167
  # 0.1.0 2019-01-30
2
168
 
3
169
  Initial release.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Dryrb Team
3
+ Copyright (c) 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,10 +1,10 @@
1
1
  [gem]: https://rubygems.org/gems/dry-schema
2
2
  [travis]: https://travis-ci.org/dry-rb/dry-schema
3
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-schema
4
- [coveralls]: https://coveralls.io/r/dry-rb/dry-schema
4
+ [chat]: https://dry-rb.zulipchat.com
5
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-schema
6
6
 
7
- # dry-schema [![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-schema [![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-schema.svg)][gem]
10
10
  [![Build Status](https://travis-ci.org/dry-rb/dry-schema.svg?branch=master)][travis]
@@ -12,9 +12,18 @@
12
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-schema/badges/coverage.svg)][codeclimate]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-schema.svg?branch=master)][inchpages]
14
14
 
15
- <!-- ## Links
15
+ ## Links
16
16
 
17
- * [Documentation](http://dry-rb.org/gems/dry-schema) -->
17
+ * [Documentation](http://dry-rb.org/gems/dry-schema)
18
+
19
+ ## Supported Ruby versions
20
+
21
+ This library officially supports following Ruby versions:
22
+
23
+ * MRI >= `2.4`
24
+ * jruby >= `9.2`
25
+
26
+ It **should** work on MRI `2.3.x` too, but there's no official support for this version.
18
27
 
19
28
  ## License
20
29
 
data/config/errors.yml CHANGED
@@ -1,91 +1,96 @@
1
1
  en:
2
- errors:
2
+ dry_schema:
3
3
  or: "or"
4
- array?: "must be an array"
5
4
 
6
- empty?: "must be empty"
5
+ errors:
6
+ array?: "must be an array"
7
7
 
8
- excludes?: "must not include %{value}"
8
+ empty?: "must be empty"
9
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}"
10
+ excludes?: "must not include %{value}"
15
11
 
16
- eql?: "must be equal to %{left}"
12
+ excluded_from?:
13
+ arg:
14
+ default: "must not be one of: %{list}"
15
+ range: "must not be one of: %{list_left} - %{list_right}"
17
16
 
18
- not_eql?: "must not be equal to %{left}"
17
+ exclusion?: "must not be one of: %{list}"
19
18
 
20
- filled?: "must be filled"
19
+ eql?: "must be equal to %{left}"
21
20
 
22
- format?: "is in invalid format"
21
+ not_eql?: "must not be equal to %{left}"
23
22
 
24
- number?: "must be a number"
23
+ filled?: "must be filled"
25
24
 
26
- odd?: "must be odd"
25
+ format?: "is in invalid format"
27
26
 
28
- even?: "must be even"
27
+ number?: "must be a number"
29
28
 
30
- gt?: "must be greater than %{num}"
29
+ odd?: "must be odd"
31
30
 
32
- gteq?: "must be greater than or equal to %{num}"
31
+ even?: "must be even"
33
32
 
34
- hash?: "must be a hash"
33
+ gt?: "must be greater than %{num}"
35
34
 
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}"
35
+ gteq?: "must be greater than or equal to %{num}"
41
36
 
42
- includes?: "must include %{value}"
37
+ hash?: "must be a hash"
43
38
 
44
- bool?: "must be boolean"
39
+ included_in?:
40
+ arg:
41
+ default: "must be one of: %{list}"
42
+ range: "must be one of: %{list_left} - %{list_right}"
45
43
 
46
- true?: "must be true"
44
+ inclusion?: "must be one of: %{list}"
47
45
 
48
- false?: "must be false"
46
+ includes?: "must include %{value}"
49
47
 
50
- int?: "must be an integer"
48
+ bool?: "must be boolean"
51
49
 
52
- float?: "must be a float"
50
+ true?: "must be true"
53
51
 
54
- decimal?: "must be a decimal"
52
+ false?: "must be false"
55
53
 
56
- date?: "must be a date"
54
+ int?: "must be an integer"
57
55
 
58
- date_time?: "must be a date time"
56
+ float?: "must be a float"
59
57
 
60
- time?: "must be a time"
58
+ decimal?: "must be a decimal"
61
59
 
62
- key?: "is missing"
60
+ date?: "must be a date"
63
61
 
64
- attr?: "is missing"
62
+ date_time?: "must be a date time"
65
63
 
66
- lt?: "must be less than %{num}"
64
+ time?: "must be a time"
67
65
 
68
- lteq?: "must be less than or equal to %{num}"
66
+ key?: "is missing"
69
67
 
70
- max_size?: "size cannot be greater than %{num}"
68
+ attr?: "is missing"
71
69
 
72
- min_size?: "size cannot be less than %{num}"
70
+ lt?: "must be less than %{num}"
73
71
 
74
- nil?: "cannot be defined"
72
+ lteq?: "must be less than or equal to %{num}"
75
73
 
76
- str?: "must be a string"
74
+ max_size?: "size cannot be greater than %{num}"
77
75
 
78
- type?: "must be %{type}"
76
+ min_size?: "size cannot be less than %{num}"
79
77
 
80
- size?:
81
- arg:
82
- default: "size must be %{size}"
83
- range: "size must be within %{size_left} - %{size_right}"
78
+ nil?: "cannot be defined"
84
79
 
85
- value:
86
- string:
87
- arg:
88
- default: "length must be %{size}"
89
- range: "length must be within %{size_left} - %{size_right}"
90
- not:
91
- empty?: "cannot be empty"
80
+ str?: "must be a string"
81
+
82
+ type?: "must be %{type}"
83
+
84
+ size?:
85
+ arg:
86
+ default: "size must be %{size}"
87
+ range: "size must be within %{size_left} - %{size_right}"
88
+
89
+ value:
90
+ string:
91
+ arg:
92
+ default: "length must be %{size}"
93
+ range: "length must be within %{size_left} - %{size_right}"
94
+
95
+ not:
96
+ empty?: "cannot be empty"
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/logic/rule_compiler'
4
+ require 'dry/schema/namespaced_rule'
2
5
  require 'dry/schema/predicate_registry'
3
6
 
4
7
  module Dry
@@ -16,6 +19,27 @@ module Dry
16
19
  super
17
20
  end
18
21
 
22
+ # @api private
23
+ def visit_and(node)
24
+ super.with(hints: false)
25
+ end
26
+
27
+ # Build a special rule that will produce namespaced failures
28
+ #
29
+ # This is needed for schemas that are namespaced and they are
30
+ # used as nested schemas
31
+ #
32
+ # @param [Array] node
33
+ # @param [Hash] opts
34
+ #
35
+ # @return [NamespacedRule]
36
+ #
37
+ # @api private
38
+ def visit_namespace(node, opts = EMPTY_HASH)
39
+ namespace, rest = node
40
+ NamespacedRule.new(namespace, visit(rest))
41
+ end
42
+
19
43
  # Return true if a given predicate is supported by this compiler
20
44
  #
21
45
  # @param [Symbol] predicate
@@ -1,6 +1,9 @@
1
- require 'delegate'
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/equalizer'
2
4
  require 'dry/configurable'
3
5
 
6
+ require 'dry/schema/constants'
4
7
  require 'dry/schema/predicate_registry'
5
8
 
6
9
  module Dry
@@ -10,42 +13,35 @@ module Dry
10
13
  # @see DSL#configure
11
14
  #
12
15
  # @api public
13
- class Config < SimpleDelegator
14
- extend Dry::Configurable
16
+ class Config
17
+ include Dry::Configurable
18
+ include Dry::Equalizer(:predicates, :messages)
15
19
 
16
- setting :predicates, Schema::PredicateRegistry.new
17
- setting :messages, :yaml
18
- setting :messages_file
19
- setting :namespace
20
- setting :rules, {}
20
+ setting(:predicates, Schema::PredicateRegistry.new)
21
21
 
22
- # Build a new config object with defaults filled in
23
- #
24
- # @api private
25
- def self.new
26
- super(struct.new(*settings.map { |key| config.public_send(key) }))
22
+ setting(:messages) do
23
+ setting(:backend, :yaml)
24
+ setting(:namespace)
25
+ setting(:load_paths, Set[DEFAULT_MESSAGES_PATH], &:dup)
26
+ setting(:top_namespace, DEFAULT_MESSAGES_ROOT)
27
27
  end
28
28
 
29
- # Build a struct with defined settings
29
+ # Return configured predicate registry
30
30
  #
31
- # @return [Struct]
31
+ # @return [Schema::PredicateRegistry]
32
32
  #
33
- # @api private
34
- def self.struct
35
- ::Struct.new(*settings)
33
+ # @api public
34
+ def predicates
35
+ config.predicates
36
36
  end
37
37
 
38
- # Expose configurable object to the provided block
39
- #
40
- # This method is used by `DSL#configure`
38
+ # Return configuration for message backend
41
39
  #
42
- # @return [Config]
40
+ # @return [Dry::Configurable::Config]
43
41
  #
44
- # @api private
45
- def configure(&block)
46
- yield(__getobj__)
47
- values.freeze
48
- freeze
42
+ # @api public
43
+ def messages
44
+ config.messages
49
45
  end
50
46
  end
51
47
  end
@@ -1,13 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
1
4
  require 'dry/core/constants'
2
5
 
3
6
  module Dry
7
+ # Common constants used across the library
8
+ #
9
+ # @api public
4
10
  module Schema
5
11
  include Core::Constants
6
12
 
13
+ LIST_SEPARATOR = ', '
14
+ QUESTION_MARK = '?'
15
+ DOT = '.'
16
+
17
+ # Path to the default set of localized messages bundled within the gem
18
+ DEFAULT_MESSAGES_PATH = Pathname(__dir__).join('../../../config/errors.yml').realpath.freeze
19
+
20
+ # Default namespace used for localized messages in YAML files
21
+ DEFAULT_MESSAGES_ROOT = 'dry_schema'
22
+
23
+ # An error raised when DSL is used in an incorrect way
7
24
  InvalidSchemaError = Class.new(StandardError)
8
- MissingMessageError = Class.new(StandardError)
9
25
 
10
- QUESTION_MARK = '?'.freeze
11
- DOT = '.'.freeze
26
+ # An error raised when a localized message cannot be found
27
+ MissingMessageError = Class.new(StandardError) do
28
+ # @api private
29
+ def initialize(path)
30
+ *rest, rule = path
31
+ super(<<~STR)
32
+ Message template for #{rule.inspect} under #{rest.join(DOT).inspect} was not found
33
+ STR
34
+ end
35
+ end
12
36
  end
13
37
  end