dsl_compose 1.6.0 → 1.8.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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +24 -0
  4. data/lib/dsl_compose/composer.rb +3 -12
  5. data/lib/dsl_compose/dsl/arguments/argument/end_with_validation.rb +30 -0
  6. data/lib/dsl_compose/dsl/arguments/argument/equal_to_validation.rb +2 -4
  7. data/lib/dsl_compose/dsl/arguments/argument/format_validation.rb +6 -4
  8. data/lib/dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation.rb +3 -8
  9. data/lib/dsl_compose/dsl/arguments/argument/greater_than_validation.rb +3 -8
  10. data/lib/dsl_compose/dsl/arguments/argument/in_validation.rb +3 -8
  11. data/lib/dsl_compose/dsl/arguments/argument/interpreter.rb +20 -0
  12. data/lib/dsl_compose/dsl/arguments/argument/length_validation.rb +3 -6
  13. data/lib/dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation.rb +3 -8
  14. data/lib/dsl_compose/dsl/arguments/argument/less_than_validation.rb +3 -8
  15. data/lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb +30 -0
  16. data/lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb +3 -8
  17. data/lib/dsl_compose/dsl/arguments/argument/not_start_with_validation.rb +30 -0
  18. data/lib/dsl_compose/dsl/arguments/argument/start_with_validation.rb +30 -0
  19. data/lib/dsl_compose/dsl/arguments/argument.rb +114 -50
  20. data/lib/dsl_compose/dsl/arguments.rb +5 -20
  21. data/lib/dsl_compose/dsl/dsl_method.rb +6 -46
  22. data/lib/dsl_compose/dsl.rb +8 -24
  23. data/lib/dsl_compose/dsls.rb +4 -13
  24. data/lib/dsl_compose/interpreter/execution/arguments.rb +24 -26
  25. data/lib/dsl_compose/interpreter/execution/method_calls/method_call.rb +0 -24
  26. data/lib/dsl_compose/interpreter/execution/method_calls.rb +6 -0
  27. data/lib/dsl_compose/interpreter/execution.rb +3 -8
  28. data/lib/dsl_compose/interpreter.rb +8 -0
  29. data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser/for_method_parser.rb +4 -10
  30. data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser.rb +4 -10
  31. data/lib/dsl_compose/parser/for_children_of_parser.rb +3 -9
  32. data/lib/dsl_compose/version.rb +1 -1
  33. data/lib/dsl_compose.rb +4 -0
  34. metadata +6 -2
@@ -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 = [
@@ -74,6 +56,10 @@ module DSLCompose
74
56
  attr_reader :equal_to_validation
75
57
  attr_reader :in_validation
76
58
  attr_reader :not_in_validation
59
+ attr_reader :end_with_validation
60
+ attr_reader :not_end_with_validation
61
+ attr_reader :start_with_validation
62
+ attr_reader :not_start_with_validation
77
63
  attr_reader :length_validation
78
64
 
79
65
  # Create a new Attribute object.
@@ -87,18 +73,18 @@ module DSLCompose
87
73
  if name.is_a? Symbol
88
74
 
89
75
  if RESERVED_ARGUMENT_NAMES.include? name
90
- raise ArgumentNameReservedError
76
+ 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
77
  end
92
78
 
93
79
  @name = name
94
80
  else
95
- raise InvalidNameError
81
+ raise InvalidNameError, "The option name `#{name}` is invalid, it must be of type symbol."
96
82
  end
97
83
 
98
84
  if type == :integer || type == :boolean || type == :float || type == :string || type == :symbol
99
85
  @type = type
100
86
  else
101
- raise InvalidTypeError
87
+ raise InvalidTypeError, "Argument type `#{type}` must be one of :integer, :boolean, :float, :string or :symbol"
102
88
  end
103
89
 
104
90
  @required = required ? true : false
@@ -111,6 +97,8 @@ module DSLCompose
111
97
  if block
112
98
  Interpreter.new(self).instance_eval(&block)
113
99
  end
100
+ rescue => e
101
+ raise e, "Error defining argument #{name}: #{e.message}", e.backtrace
114
102
  end
115
103
 
116
104
  # Set the description for this Argument to the provided value.
@@ -119,11 +107,11 @@ module DSLCompose
119
107
  # The `description` can only be set once per Argument
120
108
  def set_description description
121
109
  unless description.is_a?(String) && description.length > 0
122
- raise InvalidDescriptionError
110
+ raise InvalidDescriptionError, "The option description `#{description}` is invalid, it must be of type string and have length greater than 0."
123
111
  end
124
112
 
125
113
  if has_description?
126
- raise DescriptionAlreadyExistsError
114
+ raise DescriptionAlreadyExistsError, "The description has already been set"
127
115
  end
128
116
 
129
117
  @description = description
@@ -146,11 +134,15 @@ module DSLCompose
146
134
 
147
135
  def validate_greater_than value
148
136
  if @greater_than_validation
149
- raise ValidationAlreadyExistsError
137
+ raise ValidationAlreadyExistsError, "The validation `greater_than` has already been applied to this method option."
138
+ end
139
+
140
+ unless value.is_a?(Numeric)
141
+ raise ValidationInvalidArgumentError, value
150
142
  end
151
143
 
152
144
  unless @type == :integer || @type == :float
153
- raise ValidationIncompatibleError
145
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
154
146
  end
155
147
 
156
148
  @greater_than_validation = GreaterThanValidation.new value
@@ -158,15 +150,15 @@ module DSLCompose
158
150
 
159
151
  def validate_greater_than_or_equal_to value
160
152
  if @greater_than_or_equal_to_validation
161
- raise ValidationAlreadyExistsError
153
+ raise ValidationAlreadyExistsError, "The validation `greater_than_or_equal_to` has already been applied to this method option."
162
154
  end
163
155
 
164
156
  unless value.is_a?(Numeric)
165
- raise ValidationInvalidArgumentError
157
+ raise ValidationInvalidArgumentError, value
166
158
  end
167
159
 
168
160
  unless @type == :integer || @type == :float
169
- raise ValidationIncompatibleError
161
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
170
162
  end
171
163
 
172
164
  @greater_than_or_equal_to_validation = GreaterThanOrEqualToValidation.new value
@@ -174,15 +166,15 @@ module DSLCompose
174
166
 
175
167
  def validate_less_than value
176
168
  if @less_than_validation
177
- raise ValidationAlreadyExistsError
169
+ raise ValidationAlreadyExistsError, "The validation `less_than` has already been applied to this method option."
178
170
  end
179
171
 
180
172
  unless value.is_a?(Numeric)
181
- raise ValidationInvalidArgumentError
173
+ raise ValidationInvalidArgumentError, value
182
174
  end
183
175
 
184
176
  unless @type == :integer || @type == :float
185
- raise ValidationIncompatibleError
177
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
186
178
  end
187
179
 
188
180
  @less_than_validation = LessThanValidation.new value
@@ -190,15 +182,15 @@ module DSLCompose
190
182
 
191
183
  def validate_less_than_or_equal_to value
192
184
  if @less_than_or_equal_to_validation
193
- raise ValidationAlreadyExistsError
185
+ raise ValidationAlreadyExistsError, "The validation `less_than_or_equal_to` has already been applied to this method option."
194
186
  end
195
187
 
196
188
  unless value.is_a?(Numeric)
197
- raise ValidationInvalidArgumentError
189
+ raise ValidationInvalidArgumentError, value
198
190
  end
199
191
 
200
192
  unless @type == :integer || @type == :float
201
- raise ValidationIncompatibleError
193
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
202
194
  end
203
195
 
204
196
  @less_than_or_equal_to_validation = LessThanOrEqualToValidation.new value
@@ -206,26 +198,26 @@ module DSLCompose
206
198
 
207
199
  def validate_format regexp
208
200
  if @format_validation
209
- raise ValidationAlreadyExistsError
201
+ raise ValidationAlreadyExistsError, "The validation `format` has already been applied to this method option."
210
202
  end
211
203
 
212
204
  unless regexp.is_a? Regexp
213
- raise ValidationInvalidArgumentError
205
+ raise ValidationInvalidArgumentError, regexp
214
206
  end
215
207
 
216
208
  unless @type == :string || @type == :symbol
217
- raise ValidationIncompatibleError
209
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
218
210
  end
219
211
  @format_validation = FormatValidation.new regexp
220
212
  end
221
213
 
222
214
  def validate_equal_to value
223
215
  if @equal_to_validation
224
- raise ValidationAlreadyExistsError
216
+ raise ValidationAlreadyExistsError, "The validation `equal_to` has already been applied to this method option."
225
217
  end
226
218
 
227
219
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol || @type == :boolean
228
- raise ValidationIncompatibleError
220
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
229
221
  end
230
222
 
231
223
  @equal_to_validation = EqualToValidation.new value
@@ -233,15 +225,15 @@ module DSLCompose
233
225
 
234
226
  def validate_in values
235
227
  if @in_validation
236
- raise ValidationAlreadyExistsError
228
+ raise ValidationAlreadyExistsError, "The validation `in` has already been applied to this method option."
237
229
  end
238
230
 
239
231
  unless values.is_a? Array
240
- raise ValidationInvalidArgumentError
232
+ raise ValidationInvalidArgumentError, values
241
233
  end
242
234
 
243
235
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol
244
- raise ValidationIncompatibleError
236
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
245
237
  end
246
238
 
247
239
  @in_validation = InValidation.new values
@@ -249,27 +241,91 @@ module DSLCompose
249
241
 
250
242
  def validate_not_in values
251
243
  if @not_in_validation
252
- raise ValidationAlreadyExistsError
244
+ raise ValidationAlreadyExistsError, "The validation `not_in` has already been applied to this method option."
253
245
  end
254
246
 
255
247
  unless values.is_a? Array
256
- raise ValidationInvalidArgumentError
248
+ raise ValidationInvalidArgumentError, values
257
249
  end
258
250
 
259
251
  unless @type == :integer || @type == :float || @type == :string || @type == :symbol
260
- raise ValidationIncompatibleError
252
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
261
253
  end
262
254
 
263
255
  @not_in_validation = NotInValidation.new values
264
256
  end
265
257
 
258
+ def validate_end_with value
259
+ if @end_with_validation
260
+ raise ValidationAlreadyExistsError, "The validation `end_with` has already been applied to this method option."
261
+ end
262
+
263
+ unless value.is_a? String
264
+ raise ValidationInvalidArgumentError, value
265
+ end
266
+
267
+ unless @type == :string || @type == :symbol
268
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
269
+ end
270
+
271
+ @end_with_validation = EndWithValidation.new value
272
+ end
273
+
274
+ def validate_not_end_with value
275
+ if @not_end_with_validation
276
+ raise ValidationAlreadyExistsError, "The validation `not_end_with` has already been applied to this method option."
277
+ end
278
+
279
+ unless value.is_a? String
280
+ raise ValidationInvalidArgumentError, value
281
+ end
282
+
283
+ unless @type == :string || @type == :symbol
284
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
285
+ end
286
+
287
+ @not_end_with_validation = NotEndWithValidation.new value
288
+ end
289
+
290
+ def validate_start_with value
291
+ if @start_with_validation
292
+ raise ValidationAlreadyExistsError, "The validation `start_with` has already been applied to this method option."
293
+ end
294
+
295
+ unless value.is_a? String
296
+ raise ValidationInvalidArgumentError, value
297
+ end
298
+
299
+ unless @type == :string || @type == :symbol
300
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
301
+ end
302
+
303
+ @start_with_validation = StartWithValidation.new value
304
+ end
305
+
306
+ def validate_not_start_with value
307
+ if @not_start_with_validation
308
+ raise ValidationAlreadyExistsError, "The validation `not_start_with` has already been applied to this method option."
309
+ end
310
+
311
+ unless value.is_a? String
312
+ raise ValidationInvalidArgumentError, value
313
+ end
314
+
315
+ unless @type == :string || @type == :symbol
316
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
317
+ end
318
+
319
+ @not_start_with_validation = NotStartWithValidation.new value
320
+ end
321
+
266
322
  def validate_length maximum: nil, minimum: nil, is: nil
267
323
  if @length_validation
268
- raise ValidationAlreadyExistsError
324
+ raise ValidationAlreadyExistsError, "The validation `length` has already been applied to this method option."
269
325
  end
270
326
 
271
327
  unless @type == :string || @type == :symbol
272
- raise ValidationIncompatibleError
328
+ raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
273
329
  end
274
330
 
275
331
  @length_validation = LengthValidation.new(maximum: maximum, minimum: minimum, is: is)
@@ -294,6 +350,10 @@ module DSLCompose
294
350
  (equal_to_validation.nil? || equal_to_validation.validate!(value)) &&
295
351
  (in_validation.nil? || in_validation.validate!(value)) &&
296
352
  (not_in_validation.nil? || not_in_validation.validate!(value)) &&
353
+ (end_with_validation.nil? || end_with_validation.validate!(value)) &&
354
+ (not_end_with_validation.nil? || not_end_with_validation.validate!(value)) &&
355
+ (start_with_validation.nil? || start_with_validation.validate!(value)) &&
356
+ (not_start_with_validation.nil? || not_start_with_validation.validate!(value)) &&
297
357
  (length_validation.nil? || length_validation.validate!(value))
298
358
  end
299
359
 
@@ -303,6 +363,10 @@ module DSLCompose
303
363
  (equal_to_validation.nil? || equal_to_validation.validate!(value)) &&
304
364
  (in_validation.nil? || in_validation.validate!(value)) &&
305
365
  (not_in_validation.nil? || not_in_validation.validate!(value)) &&
366
+ (end_with_validation.nil? || end_with_validation.validate!(value)) &&
367
+ (not_end_with_validation.nil? || not_end_with_validation.validate!(value)) &&
368
+ (start_with_validation.nil? || start_with_validation.validate!(value)) &&
369
+ (not_start_with_validation.nil? || not_start_with_validation.validate!(value)) &&
306
370
  (length_validation.nil? || length_validation.validate!(value))
307
371
  end
308
372
 
@@ -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)
@@ -3,58 +3,16 @@
3
3
  module DSLCompose
4
4
  class DSL
5
5
  class DSLMethod
6
- class ArgumentDoesNotExistError < StandardError
7
- def message
8
- "This argument does not exist for this DSLMethod"
9
- end
10
- end
11
-
12
6
  class InvalidNameError < StandardError
13
- def message
14
- "The method #{method_name} is invalid, it must be of type symbol"
15
- end
16
7
  end
17
8
 
18
9
  class MethodNameIsReservedError < StandardError
19
- def message
20
- "This method already would override an existing internal method"
21
- end
22
10
  end
23
11
 
24
12
  class InvalidDescriptionError < StandardError
25
- def message
26
- "The DSL method description is invalid, it must be of type string and have length greater than 0"
27
- end
28
13
  end
29
14
 
30
15
  class DescriptionAlreadyExistsError < StandardError
31
- def message
32
- "The description has already been set"
33
- end
34
- end
35
-
36
- class ArgumentOrderingError < StandardError
37
- def message
38
- "Required arguments can not be added after optional ones"
39
- end
40
- end
41
-
42
- class ArgumentAlreadyExistsError < StandardError
43
- def message
44
- "An argument with this name already exists for this DSL method"
45
- end
46
- end
47
-
48
- class RequestedOptionalArgumentIsRequiredError < StandardError
49
- def message
50
- "A specific argument which was expected to be optional was requested, but the argument found was flagged as required"
51
- end
52
- end
53
-
54
- class RequestedRequiredArgumentIsOptionalError < StandardError
55
- def message
56
- "A specific argument which was expected to be required was requested, but the argument found was flagged as optional"
57
- end
58
16
  end
59
17
 
60
18
  # The name of this DSLMethod.
@@ -82,12 +40,12 @@ module DSLCompose
82
40
 
83
41
  # don't allow methods to override existing internal methods
84
42
  if Class.respond_to? name
85
- raise MethodNameIsReservedError
43
+ raise MethodNameIsReservedError, "This method #{name} would override an existing internal method"
86
44
  end
87
45
 
88
46
  @name = name
89
47
  else
90
- raise InvalidNameError
48
+ raise InvalidNameError, "The method name `#{name}` is invalid, it must be of type symbol"
91
49
  end
92
50
 
93
51
  @unique = unique ? true : false
@@ -101,6 +59,8 @@ module DSLCompose
101
59
  if block
102
60
  Interpreter.new(self).instance_eval(&block)
103
61
  end
62
+ rescue => e
63
+ raise e, "Error defining method #{name}: #{e.message}", e.backtrace
104
64
  end
105
65
 
106
66
  # Set the description for this DSLMethod to the provided value.
@@ -109,11 +69,11 @@ module DSLCompose
109
69
  # The `description` can only be set once per DSLMethod
110
70
  def set_description description
111
71
  unless description.is_a?(String) && description.length > 0
112
- raise InvalidDescriptionError
72
+ raise InvalidDescriptionError, "The DSL method description `#{description}` is invalid, it must be of type string and have length greater than 0"
113
73
  end
114
74
 
115
75
  if has_description?
116
- raise DescriptionAlreadyExistsError
76
+ raise DescriptionAlreadyExistsError, "The description has already been set"
117
77
  end
118
78
 
119
79
  @description = description
@@ -7,39 +7,21 @@ module DSLCompose
7
7
  # by calling `define_dsl` in a class and passing it a block which contains the DSL definition
8
8
  class DSL
9
9
  class MethodDoesNotExistError < StandardError
10
- def message
11
- "This method does not exist for this DSL"
12
- end
13
10
  end
14
11
 
15
12
  class MethodAlreadyExistsError < StandardError
16
- def message
17
- "This method already exists for this DSL"
18
- end
19
13
  end
20
14
 
21
15
  class InvalidNameError < StandardError
22
- def message
23
- "This DSL name is invalid, it must be of type symbol"
24
- end
25
16
  end
26
17
 
27
18
  class InvalidDescriptionError < StandardError
28
- def message
29
- "This DSL description is invalid, it must be of type string and have length greater than 0"
30
- end
31
19
  end
32
20
 
33
21
  class DescriptionAlreadyExistsError < StandardError
34
- def message
35
- "The DSL description has already been set"
36
- end
37
22
  end
38
23
 
39
24
  class NoBlockProvidedError < StandardError
40
- def message
41
- "No block was provided for this DSL"
42
- end
43
25
  end
44
26
 
45
27
  # The name of this DSL.
@@ -64,7 +46,7 @@ module DSLCompose
64
46
  if name.is_a? Symbol
65
47
  @name = name
66
48
  else
67
- raise InvalidNameError
49
+ raise InvalidNameError, "The DSL name `#{name}` is invalid, it must be of type symbol"
68
50
  end
69
51
 
70
52
  @klass = klass
@@ -81,8 +63,10 @@ module DSLCompose
81
63
  # would have access to all of the methods defined in here.
82
64
  Interpreter.new(self).instance_eval(&block)
83
65
  else
84
- raise NoBlockProvidedError
66
+ raise NoBlockProvidedError, "No block was provided for this DSL"
85
67
  end
68
+ rescue => e
69
+ raise e, "Error defining DSL #{@name} on #{@klass}: #{e.message}", e.backtrace
86
70
  end
87
71
 
88
72
  # Set the description for this DSL to the provided value.
@@ -91,11 +75,11 @@ module DSLCompose
91
75
  # The `description` can only be set once per DSL
92
76
  def set_description description
93
77
  unless description.is_a?(String) && description.length > 0
94
- raise InvalidDescriptionError
78
+ raise InvalidDescriptionError, "The DSL description `#{description}` is invalid, it must be of type string and have length greater than 0"
95
79
  end
96
80
 
97
81
  if has_description?
98
- raise DescriptionAlreadyExistsError
82
+ raise DescriptionAlreadyExistsError, "The DSL description has already been set"
99
83
  end
100
84
 
101
85
  @description = description
@@ -112,7 +96,7 @@ module DSLCompose
112
96
  # Method `name` must be unique within the DSL.
113
97
  def add_method name, unique, required, &block
114
98
  if has_dsl_method? name
115
- raise MethodAlreadyExistsError
99
+ raise MethodAlreadyExistsError, "The method `#{name}` already exists for this DSL"
116
100
  end
117
101
 
118
102
  @dsl_methods[name] = DSLMethod.new(name, unique, required, &block)
@@ -139,7 +123,7 @@ module DSLCompose
139
123
  if has_dsl_method? name
140
124
  @dsl_methods[name]
141
125
  else
142
- raise MethodDoesNotExistError
126
+ raise MethodDoesNotExistError, "The method `#{name}` does not exist for this DSL"
143
127
  end
144
128
  end
145
129
 
@@ -3,21 +3,12 @@
3
3
  module DSLCompose
4
4
  module DSLs
5
5
  class ClassDSLDefinitionDoesNotExistError < StandardError
6
- def message
7
- "The requested DSL does not exist on this class"
8
- end
9
6
  end
10
7
 
11
8
  class DSLAlreadyExistsError < StandardError
12
- def message
13
- "A DSL with this name already exists"
14
- end
15
9
  end
16
10
 
17
11
  class NoDSLDefinitionsForClassError < StandardError
18
- def message
19
- "No DSLs have been defined for this class"
20
- end
21
12
  end
22
13
 
23
14
  # an object to hold all of the defined DSLs in our application, the DSLs are
@@ -30,7 +21,7 @@ module DSLCompose
30
21
  @dsls[klass] ||= {}
31
22
 
32
23
  if @dsls[klass].key? name
33
- raise DSLAlreadyExistsError
24
+ raise DSLAlreadyExistsError, "A DSL with the name `#{name}` already exists"
34
25
  end
35
26
 
36
27
  @dsls[klass][name] = DSLCompose::DSL.new(name, klass)
@@ -53,7 +44,7 @@ module DSLCompose
53
44
  if @dsls.key? klass
54
45
  @dsls[klass].values
55
46
  else
56
- raise NoDSLDefinitionsForClassError
47
+ raise NoDSLDefinitionsForClassError, "No DSLs have been defined for this class"
57
48
  end
58
49
  end
59
50
 
@@ -64,10 +55,10 @@ module DSLCompose
64
55
  if @dsls[klass].key? name
65
56
  @dsls[klass][name]
66
57
  else
67
- raise ClassDSLDefinitionDoesNotExistError
58
+ raise ClassDSLDefinitionDoesNotExistError, "The requested DSL `#{name}` does not exist on this class"
68
59
  end
69
60
  else
70
- raise NoDSLDefinitionsForClassError
61
+ raise NoDSLDefinitionsForClassError, "No DSLs have been defined for this class"
71
62
  end
72
63
  end
73
64