dsl_compose 1.5.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/lib/dsl_compose/composer.rb +3 -12
  4. data/lib/dsl_compose/dsl/arguments/argument/equal_to_validation.rb +1 -4
  5. data/lib/dsl_compose/dsl/arguments/argument/format_validation.rb +1 -4
  6. data/lib/dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation.rb +2 -8
  7. data/lib/dsl_compose/dsl/arguments/argument/greater_than_validation.rb +2 -8
  8. data/lib/dsl_compose/dsl/arguments/argument/in_validation.rb +2 -8
  9. data/lib/dsl_compose/dsl/arguments/argument/length_validation.rb +3 -6
  10. data/lib/dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation.rb +2 -8
  11. data/lib/dsl_compose/dsl/arguments/argument/less_than_validation.rb +2 -8
  12. data/lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb +2 -8
  13. data/lib/dsl_compose/dsl/arguments/argument.rb +38 -50
  14. data/lib/dsl_compose/dsl/arguments.rb +5 -20
  15. data/lib/dsl_compose/dsl/dsl_method.rb +6 -46
  16. data/lib/dsl_compose/dsl.rb +8 -24
  17. data/lib/dsl_compose/dsls.rb +4 -13
  18. data/lib/dsl_compose/interpreter/execution/arguments.rb +24 -26
  19. data/lib/dsl_compose/interpreter/execution/method_calls/method_call.rb +0 -24
  20. data/lib/dsl_compose/interpreter/execution/method_calls.rb +6 -0
  21. data/lib/dsl_compose/interpreter/execution.rb +3 -8
  22. data/lib/dsl_compose/interpreter.rb +15 -0
  23. data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser/for_method_parser.rb +4 -10
  24. data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser.rb +4 -10
  25. data/lib/dsl_compose/parser/for_children_of_parser.rb +3 -9
  26. data/lib/dsl_compose/version.rb +1 -1
  27. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f215d3a5226d56e6f0f5e62b340e0212607a52c3097228f7fc24ef1f5028a20
4
- data.tar.gz: afcf1aa8a22966ca83475f7e0d41780c5e0d44e50b13dc91b33a71011b6d1fc4
3
+ metadata.gz: 461fe3b90a0a36703aee0be51b3594472d2fc55ff1eab2b6b5bfabd851446d09
4
+ data.tar.gz: 65ba43be5dfcefbaf5588744b66fcd73a8266abbea65bcb59699132c43ed47a7
5
5
  SHA512:
6
- metadata.gz: fff6880b4032551cabd769fa1c2c6eda13179f4b1e50cb652bdef9a6ecd0055e45994235d0ebb78ee06445086368c304279fa04feddcde41b78e046677aea86c
7
- data.tar.gz: 409bae7843d156e2c1e6854ebd87381c2eafcccc8adaf3cd2adfbcc076282efde0d0d12c69fb661f95ac0404c7bfd1b28328bdc6e54f211790fb62571b1dd7a0
6
+ metadata.gz: 9d2b86c2398b49217ba29152f68f6666e0bcbe926d4adadaac29b4f4a3d8500b120192c469c4fa25f68b68c58e73782459356a7845bcabb0237076521e4e0f37
7
+ data.tar.gz: 4f58959006d911cb13d75ccddc1871416736236d0e278844f6beb1c22a546d2e8d3620230931a2108c8949ad346a65ce27f3ae437fd8d55e5563603ad8421d24
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.7.0](https://github.com/craigulliott/dsl_compose/compare/v1.6.0...v1.7.0) (2023-07-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * better error messages ([#19](https://github.com/craigulliott/dsl_compose/issues/19)) ([a9afa6c](https://github.com/craigulliott/dsl_compose/commit/a9afa6cb1b7482d0d7a646b6872ca5e969393eb7))
9
+
10
+ ## [1.6.0](https://github.com/craigulliott/dsl_compose/compare/v1.5.0...v1.6.0) (2023-07-07)
11
+
12
+
13
+ ### Features
14
+
15
+ * added an interpreter clear method to erase state between tests ([#17](https://github.com/craigulliott/dsl_compose/issues/17)) ([9d0a0c9](https://github.com/craigulliott/dsl_compose/commit/9d0a0c9c521bed61f08fecaa388d1410f513498b))
16
+
3
17
  ## [1.5.0](https://github.com/craigulliott/dsl_compose/compare/v1.4.0...v1.5.0) (2023-07-07)
4
18
 
5
19
 
@@ -3,26 +3,17 @@
3
3
  module DSLCompose
4
4
  module Composer
5
5
  class ComposerAlreadyInstalledError < StandardError
6
- def message
7
- "This module has already been included or the define_dsl singleton method already exists for this class."
8
- end
9
6
  end
10
7
 
11
8
  class MethodAlreadyExistsWithThisDSLNameError < StandardError
12
- def message
13
- "The `define_dsl` singleton method already exists for this class."
14
- end
15
9
  end
16
10
 
17
11
  class GetDSLExecutionResultsMethodAlreadyExistsError < StandardError
18
- def message
19
- "The `dsls` singleton method already exists for this class."
20
- end
21
12
  end
22
13
 
23
14
  def self.included klass
24
15
  if (klass.private_methods + klass.methods).include? :define_dsl
25
- raise ComposerAlreadyInstalledError
16
+ raise ComposerAlreadyInstalledError, "This module has already been included or the define_dsl singleton method already exists for this class."
26
17
  end
27
18
 
28
19
  # create an interpreter for this class which will be shared by all child classes and all
@@ -31,7 +22,7 @@ module DSLCompose
31
22
 
32
23
  # return a specific DSL which is defined for this class
33
24
  if klass.respond_to? :dsls
34
- raise GetDSLExecutionResultsMethodAlreadyExistsError
25
+ raise GetDSLExecutionResultsMethodAlreadyExistsError, "The `dsls` singleton method already exists for this class."
35
26
  end
36
27
 
37
28
  klass.define_singleton_method :dsls do
@@ -52,7 +43,7 @@ module DSLCompose
52
43
 
53
44
  # ensure that creating this DSL will not override any existing methods on this class
54
45
  if respond_to? name
55
- raise MethodAlreadyExistsWithThisDSLNameError
46
+ raise MethodAlreadyExistsWithThisDSLNameError, "The `define_dsl` singleton method `#{name}` already exists for this class."
56
47
  end
57
48
 
58
49
  # add a singleton method with the name of this new DSL onto our class, this is how our new DSL will be accessed
@@ -6,9 +6,6 @@ module DSLCompose
6
6
  class Argument
7
7
  class EqualToValidation
8
8
  class ValidationFailedError < StandardError
9
- def message
10
- "The argument is invalid"
11
- end
12
9
  end
13
10
 
14
11
  def initialize value
@@ -16,7 +13,7 @@ module DSLCompose
16
13
  end
17
14
 
18
15
  def validate! value
19
- raise ValidationFailedError unless value == @value
16
+ raise ValidationFailedError, "The argument is invalid. Expected #{@value} but received #{value}" unless value == @value
20
17
  end
21
18
  end
22
19
  end
@@ -6,9 +6,6 @@ module DSLCompose
6
6
  class Argument
7
7
  class FormatValidation
8
8
  class ValidationFailedError < StandardError
9
- def message
10
- "The argument is invalid"
11
- end
12
9
  end
13
10
 
14
11
  def initialize regex
@@ -16,7 +13,7 @@ module DSLCompose
16
13
  end
17
14
 
18
15
  def validate! value
19
- raise ValidationFailedError if @regex.match(value).nil?
16
+ raise ValidationFailedError, "The argument is invalid. Expected format #{@regex} but received #{value}" if @regex.match(value).nil?
20
17
  end
21
18
  end
22
19
  end
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class GreaterThanOrEqualToValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize value
21
15
  unless value.is_a?(Numeric)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type number"
23
17
  end
24
18
 
25
19
  @value = value
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError unless value >= @value
23
+ raise ValidationFailedError, "The argument is invalid. Expected greater than or equal to #{@value} but received #{value}" unless value >= @value
30
24
  end
31
25
  end
32
26
  end
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class GreaterThanValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize value
21
15
  unless value.is_a?(Numeric)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type number"
23
17
  end
24
18
 
25
19
  @value = value
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError unless value > @value
23
+ raise ValidationFailedError, "The argument is invalid. Expected greater than #{@value} but received #{value}" unless value > @value
30
24
  end
31
25
  end
32
26
  end
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class InValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize values
21
15
  unless values.is_a?(Array)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
23
17
  end
24
18
 
25
19
  @values = values
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError unless @values.include? value
23
+ raise ValidationFailedError, "The argument is invalid. Expected in #{@values} but received #{value}" unless @values.include? value
30
24
  end
31
25
  end
32
26
  end
@@ -6,9 +6,6 @@ module DSLCompose
6
6
  class Argument
7
7
  class LengthValidation
8
8
  class ValidationFailedError < StandardError
9
- def message
10
- "The argument is invalid"
11
- end
12
9
  end
13
10
 
14
11
  def initialize maximum: nil, minimum: nil, is: nil
@@ -20,17 +17,17 @@ module DSLCompose
20
17
  def validate! value
21
18
  maximum = @maximum
22
19
  unless maximum.nil?
23
- raise ValidationFailedError if value.length > maximum
20
+ raise ValidationFailedError, "The argument is invalid. Expected #{value} to be less than or equal to #{maximum} characters" if value.length > maximum
24
21
  end
25
22
 
26
23
  minimum = @minimum
27
24
  unless minimum.nil?
28
- raise ValidationFailedError if value.length < minimum
25
+ raise ValidationFailedError, "The argument is invalid. Expected #{value} to be greater than or equal to #{minimum} characters" if value.length < minimum
29
26
  end
30
27
 
31
28
  is = @is
32
29
  unless is.nil?
33
- raise ValidationFailedError if value.length != is
30
+ raise ValidationFailedError, "The argument is invalid. Expected #{value} to be #{is} characters long" if value.length != is
34
31
  end
35
32
 
36
33
  true
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class LessThanOrEqualToValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize value
21
15
  unless value.is_a?(Numeric)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type number"
23
17
  end
24
18
 
25
19
  @value = value
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError unless value <= @value
23
+ raise ValidationFailedError, "The argument is invalid. Expected less than or equal to #{@value} but received #{value}" unless value <= @value
30
24
  end
31
25
  end
32
26
  end
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class LessThanValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize value
21
15
  unless value.is_a?(Numeric)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type number"
23
17
  end
24
18
 
25
19
  @value = value
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError unless value < @value
23
+ raise ValidationFailedError, "The argument is invalid. Expected less than #{@value} but received #{value}" unless value < @value
30
24
  end
31
25
  end
32
26
  end
@@ -6,27 +6,21 @@ module DSLCompose
6
6
  class Argument
7
7
  class NotInValidation
8
8
  class InvalidValueError < StandardError
9
- def message
10
- "The value provided to validate_greater_than must be a number"
11
- end
12
9
  end
13
10
 
14
11
  class ValidationFailedError < StandardError
15
- def message
16
- "The argument is invalid"
17
- end
18
12
  end
19
13
 
20
14
  def initialize values
21
15
  unless values.is_a?(Array)
22
- raise InvalidValueError
16
+ raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
23
17
  end
24
18
 
25
19
  @values = values
26
20
  end
27
21
 
28
22
  def validate! value
29
- raise ValidationFailedError if @values.include?(value)
23
+ raise ValidationFailedError, "The argument is invalid. Expected not in #{@values} but received #{value}" if @values.include?(value)
30
24
  end
31
25
  end
32
26
  end
@@ -5,45 +5,27 @@ module DSLCompose
5
5
  class Arguments
6
6
  class Argument
7
7
  class ValidationIncompatibleError < StandardError
8
- def message
9
- "The validation is not compatible with this argument type"
10
- end
11
8
  end
12
9
 
13
10
  class ValidationAlreadyExistsError < StandardError
14
- def message
15
- "This validation has already been applied to this method option."
16
- end
17
11
  end
18
12
 
19
13
  class InvalidTypeError < StandardError
20
- def message
21
- "Argument type must be one of :integer, :boolean, :float, :string or :symbol"
22
- end
23
14
  end
24
15
 
25
16
  class InvalidNameError < StandardError
26
- def message
27
- "The option name is invalid, it must be of type symbol."
28
- end
29
17
  end
30
18
 
31
19
  class InvalidDescriptionError < StandardError
32
- def message
33
- "The option description is invalid, it must be of type string and have length greater than 0."
34
- end
35
20
  end
36
21
 
37
22
  class DescriptionAlreadyExistsError < StandardError
38
- def message
39
- "The description has already been set"
40
- end
41
23
  end
42
24
 
43
25
  class ArgumentNameReservedError < StandardError
44
- def message
45
- "This argument name is a reserved word. The names #{RESERVED_ARGUMENT_NAMES.join ", "} can not be used here because the Parser uses it to express a structural part of the DSL"
46
- end
26
+ end
27
+
28
+ class ValidationInvalidArgumentError < StandardError
47
29
  end
48
30
 
49
31
  RESERVED_ARGUMENT_NAMES = [
@@ -87,18 +69,18 @@ module DSLCompose
87
69
  if name.is_a? Symbol
88
70
 
89
71
  if RESERVED_ARGUMENT_NAMES.include? name
90
- raise ArgumentNameReservedError
72
+ raise ArgumentNameReservedError, "This argument name `#{name}` is a reserved word. The names #{RESERVED_ARGUMENT_NAMES.join ", "} can not be used here because the Parser uses them to express a structural part of the DSL"
91
73
  end
92
74
 
93
75
  @name = name
94
76
  else
95
- raise InvalidNameError
77
+ raise InvalidNameError, "The option name `#{name}` is invalid, it must be of type symbol."
96
78
  end
97
79
 
98
80
  if type == :integer || type == :boolean || type == :float || type == :string || type == :symbol
99
81
  @type = type
100
82
  else
101
- raise InvalidTypeError
83
+ raise InvalidTypeError, "Argument type `#{type}` must be one of :integer, :boolean, :float, :string or :symbol"
102
84
  end
103
85
 
104
86
  @required = required ? true : false
@@ -111,6 +93,8 @@ module DSLCompose
111
93
  if block
112
94
  Interpreter.new(self).instance_eval(&block)
113
95
  end
96
+ rescue => e
97
+ raise e, "Error defining argument #{name}: #{e.message}", e.backtrace
114
98
  end
115
99
 
116
100
  # Set the description for this Argument to the provided value.
@@ -119,11 +103,11 @@ module DSLCompose
119
103
  # The `description` can only be set once per Argument
120
104
  def set_description description
121
105
  unless description.is_a?(String) && description.length > 0
122
- raise InvalidDescriptionError
106
+ raise InvalidDescriptionError, "The option description `#{description}` is invalid, it must be of type string and have length greater than 0."
123
107
  end
124
108
 
125
109
  if has_description?
126
- raise DescriptionAlreadyExistsError
110
+ raise DescriptionAlreadyExistsError, "The description has already been set"
127
111
  end
128
112
 
129
113
  @description = description
@@ -146,11 +130,15 @@ module DSLCompose
146
130
 
147
131
  def validate_greater_than value
148
132
  if @greater_than_validation
149
- raise ValidationAlreadyExistsError
133
+ raise ValidationAlreadyExistsError, "The validation `greater_than` has already been applied to this method option."
134
+ end
135
+
136
+ unless value.is_a?(Numeric)
137
+ raise ValidationInvalidArgumentError, value
150
138
  end
151
139
 
152
140
  unless @type == :integer || @type == :float
153
- raise ValidationIncompatibleError
141
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
154
142
  end
155
143
 
156
144
  @greater_than_validation = GreaterThanValidation.new value
@@ -158,15 +146,15 @@ module DSLCompose
158
146
 
159
147
  def validate_greater_than_or_equal_to value
160
148
  if @greater_than_or_equal_to_validation
161
- raise ValidationAlreadyExistsError
149
+ raise ValidationAlreadyExistsError, "The validation `greater_than_or_equal_to` has already been applied to this method option."
162
150
  end
163
151
 
164
152
  unless value.is_a?(Numeric)
165
- raise ValidationInvalidArgumentError
153
+ raise ValidationInvalidArgumentError, value
166
154
  end
167
155
 
168
156
  unless @type == :integer || @type == :float
169
- raise ValidationIncompatibleError
157
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
170
158
  end
171
159
 
172
160
  @greater_than_or_equal_to_validation = GreaterThanOrEqualToValidation.new value
@@ -174,15 +162,15 @@ module DSLCompose
174
162
 
175
163
  def validate_less_than value
176
164
  if @less_than_validation
177
- raise ValidationAlreadyExistsError
165
+ raise ValidationAlreadyExistsError, "The validation `less_than` has already been applied to this method option."
178
166
  end
179
167
 
180
168
  unless value.is_a?(Numeric)
181
- raise ValidationInvalidArgumentError
169
+ raise ValidationInvalidArgumentError, value
182
170
  end
183
171
 
184
172
  unless @type == :integer || @type == :float
185
- raise ValidationIncompatibleError
173
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
186
174
  end
187
175
 
188
176
  @less_than_validation = LessThanValidation.new value
@@ -190,15 +178,15 @@ module DSLCompose
190
178
 
191
179
  def validate_less_than_or_equal_to value
192
180
  if @less_than_or_equal_to_validation
193
- raise ValidationAlreadyExistsError
181
+ raise ValidationAlreadyExistsError, "The validation `less_than_or_equal_to` has already been applied to this method option."
194
182
  end
195
183
 
196
184
  unless value.is_a?(Numeric)
197
- raise ValidationInvalidArgumentError
185
+ raise ValidationInvalidArgumentError, value
198
186
  end
199
187
 
200
188
  unless @type == :integer || @type == :float
201
- raise ValidationIncompatibleError
189
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
202
190
  end
203
191
 
204
192
  @less_than_or_equal_to_validation = LessThanOrEqualToValidation.new value
@@ -206,26 +194,26 @@ module DSLCompose
206
194
 
207
195
  def validate_format regexp
208
196
  if @format_validation
209
- raise ValidationAlreadyExistsError
197
+ raise ValidationAlreadyExistsError, "The validation `format` has already been applied to this method option."
210
198
  end
211
199
 
212
200
  unless regexp.is_a? Regexp
213
- raise ValidationInvalidArgumentError
201
+ raise ValidationInvalidArgumentError, regexp
214
202
  end
215
203
 
216
204
  unless @type == :string || @type == :symbol
217
- raise ValidationIncompatibleError
205
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
218
206
  end
219
207
  @format_validation = FormatValidation.new regexp
220
208
  end
221
209
 
222
210
  def validate_equal_to value
223
211
  if @equal_to_validation
224
- raise ValidationAlreadyExistsError
212
+ raise ValidationAlreadyExistsError, "The validation `equal_to` has already been applied to this method option."
225
213
  end
226
214
 
227
215
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol || @type == :boolean
228
- raise ValidationIncompatibleError
216
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
229
217
  end
230
218
 
231
219
  @equal_to_validation = EqualToValidation.new value
@@ -233,15 +221,15 @@ module DSLCompose
233
221
 
234
222
  def validate_in values
235
223
  if @in_validation
236
- raise ValidationAlreadyExistsError
224
+ raise ValidationAlreadyExistsError, "The validation `in` has already been applied to this method option."
237
225
  end
238
226
 
239
227
  unless values.is_a? Array
240
- raise ValidationInvalidArgumentError
228
+ raise ValidationInvalidArgumentError, values
241
229
  end
242
230
 
243
231
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol
244
- raise ValidationIncompatibleError
232
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
245
233
  end
246
234
 
247
235
  @in_validation = InValidation.new values
@@ -249,15 +237,15 @@ module DSLCompose
249
237
 
250
238
  def validate_not_in values
251
239
  if @not_in_validation
252
- raise ValidationAlreadyExistsError
240
+ raise ValidationAlreadyExistsError, "The validation `not_in` has already been applied to this method option."
253
241
  end
254
242
 
255
243
  unless values.is_a? Array
256
- raise ValidationInvalidArgumentError
244
+ raise ValidationInvalidArgumentError, values
257
245
  end
258
246
 
259
247
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol
260
- raise ValidationIncompatibleError
248
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
261
249
  end
262
250
 
263
251
  @not_in_validation = NotInValidation.new values
@@ -265,11 +253,11 @@ module DSLCompose
265
253
 
266
254
  def validate_length maximum: nil, minimum: nil, is: nil
267
255
  if @length_validation
268
- raise ValidationAlreadyExistsError
256
+ raise ValidationAlreadyExistsError, "The validation `length` has already been applied to this method option."
269
257
  end
270
258
 
271
259
  unless @type == :string || @type == :symbol
272
- raise ValidationIncompatibleError
260
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
273
261
  end
274
262
 
275
263
  @length_validation = LengthValidation.new(maximum: maximum, minimum: minimum, is: is)
@@ -4,33 +4,18 @@ module DSLCompose
4
4
  class DSL
5
5
  class Arguments
6
6
  class ArgumentDoesNotExistError < StandardError
7
- def message
8
- "This argument does not exist for this DSLMethod"
9
- end
10
7
  end
11
8
 
12
9
  class ArgumentOrderingError < StandardError
13
- def message
14
- "Required arguments can not be added after optional ones"
15
- end
16
10
  end
17
11
 
18
12
  class ArgumentAlreadyExistsError < StandardError
19
- def message
20
- "An argument with this name already exists for this DSL method"
21
- end
22
13
  end
23
14
 
24
15
  class RequestedOptionalArgumentIsRequiredError < StandardError
25
- def message
26
- "A specific argument which was expected to be optional was requested, but the argument found was flagged as required"
27
- end
28
16
  end
29
17
 
30
18
  class RequestedRequiredArgumentIsOptionalError < StandardError
31
- def message
32
- "A specific argument which was expected to be required was requested, but the argument found was flagged as optional"
33
- end
34
19
  end
35
20
 
36
21
  def initialize
@@ -58,7 +43,7 @@ module DSLCompose
58
43
  if has_argument? name
59
44
  @arguments[name]
60
45
  else
61
- raise ArgumentDoesNotExistError
46
+ raise ArgumentDoesNotExistError, "The argument `#{name}` does not exist for this DSLMethod"
62
47
  end
63
48
  end
64
49
 
@@ -69,7 +54,7 @@ module DSLCompose
69
54
  if arg.optional?
70
55
  @arguments[name]
71
56
  else
72
- raise RequestedOptionalArgumentIsRequiredError
57
+ raise RequestedOptionalArgumentIsRequiredError, "A specific argument `#{name}` which was expected to be optional was requested, but the argument found was flagged as required"
73
58
  end
74
59
  end
75
60
 
@@ -80,7 +65,7 @@ module DSLCompose
80
65
  if arg.required?
81
66
  @arguments[name]
82
67
  else
83
- raise RequestedRequiredArgumentIsOptionalError
68
+ raise RequestedRequiredArgumentIsOptionalError, "A specific argument `#{name}` which was expected to be required was requested, but the argument found was flagged as optional"
84
69
  end
85
70
  end
86
71
 
@@ -98,12 +83,12 @@ module DSLCompose
98
83
  # or optional on the method which is exposed in our DSL.
99
84
  def add_argument name, required, type, &block
100
85
  if @arguments.key? name
101
- raise ArgumentAlreadyExistsError
86
+ raise ArgumentAlreadyExistsError, "An argument with the name `#{name}` already exists for this DSL method"
102
87
  end
103
88
 
104
89
  # required arguments may not come after optional ones
105
90
  if required && optional_arguments.any?
106
- raise ArgumentOrderingError
91
+ raise ArgumentOrderingError, "Required arguments can not be added after optional ones"
107
92
  end
108
93
 
109
94
  @arguments[name] = Argument.new(name, required, type, &block)