dsl_compose 2.3.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fab8958e567edd7044bfef529f74c21930c7c1fba06bfd359d905249fc2d17c
4
- data.tar.gz: a167ad2aaaf44b226b2884ee0f4d6447444ebe0629453ca5f288430c5198e683
3
+ metadata.gz: 6b29a5bddf2a3f304e22318d9ef0d2f1dc9efbb195618b1b296f33affff3d4b0
4
+ data.tar.gz: 06141a53c94fdfa21265df75594b627e30dd37d13d2943e83dda5cad29de9de4
5
5
  SHA512:
6
- metadata.gz: fcd2f5ff1b501cffd445d937f4a96e158250e8e76e48969d54760511dc339dc90e0d7d1d3f4f2ed5a14ffc0eafe037a8833122a0f649c071a8188e1819901bb4
7
- data.tar.gz: e1df9014ea4b8a20db709e44284ce320a92808085aee70004a4bac19609fad866f271426e2e86c7ec46919f21795f55c91411b1404f73cfd0349544ef71ee408
6
+ metadata.gz: 8f605f57dbf60fb77e7633d4631d7c5423d9614e28cce18e9e05fcca637d0b35b49b1d71c504d50289d527019c48f5a0a96588ab9cb25ba5d1c651c4ae6570f8
7
+ data.tar.gz: 19619027a3a21f8506cd077a927a719284b378d5d4cb2f2f11d5264a487442c2f44da2a1780684603a0154348c89c2359459b776077380da8f3a1093a15a72b6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.5.0](https://github.com/craigulliott/dsl_compose/compare/v2.4.0...v2.5.0) (2023-08-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * you can call validators which accept arrays (such as `validate_in`) multiple times and they will be combined ([e1b4411](https://github.com/craigulliott/dsl_compose/commit/e1b441176768726cecd828e303781a57d4e36750))
9
+
10
+ ## [2.4.0](https://github.com/craigulliott/dsl_compose/compare/v2.3.0...v2.4.0) (2023-07-31)
11
+
12
+
13
+ ### Features
14
+
15
+ * access an ExecutionReader object from within a parser ([53e9c29](https://github.com/craigulliott/dsl_compose/commit/53e9c29073389217d8526c43eec67325587c45b9))
16
+
3
17
  ## [2.3.0](https://github.com/craigulliott/dsl_compose/compare/v2.2.2...v2.3.0) (2023-07-28)
4
18
 
5
19
 
data/README.md CHANGED
@@ -274,8 +274,13 @@ class MyParser < DSLCompose::Parser
274
274
  # then the requested dsl argument must be present on all DSLs otherwise an
275
275
  # error will be raised. The parser is aware of class inheritance, and will
276
276
  # consider a DSL to have been executed on the actual class it was used, and
277
- # any classes which are descendants of that class
278
- for_dsl [:dsl1, :dsl2] do |dsl_name:, a_dsl_argument:|
277
+ # any classes which are descendants of that class.
278
+ #
279
+ # You can also request an ExecutionReader object here by including the
280
+ # argument `:reader`. The resulting reader object will allow to to access the methods
281
+ # which were called within this use of your DSL. There is more documentation about
282
+ # Reader classes below.
283
+ for_dsl [:dsl1, :dsl2] do |dsl_name:, a_dsl_argument:, reader:|
279
284
  description <<-DESCRIPTION
280
285
  You can optionally provide a description of anything specific that your parser
281
286
  does in this block, this description will be used when generating documentation.
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,11 +12,16 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  unless values.is_a?(Array)
16
21
  raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
17
22
  end
18
23
 
19
- @values = values
24
+ @values += values
20
25
  end
21
26
 
22
27
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,11 +12,16 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  unless values.is_a?(Array)
16
21
  raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
17
22
  end
18
23
 
19
- @values = values
24
+ @values += values
20
25
  end
21
26
 
22
27
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -230,10 +230,6 @@ module DSLCompose
230
230
  end
231
231
 
232
232
  def validate_in values
233
- if @in_validation
234
- raise ValidationAlreadyExistsError, "The validation `in` has already been applied to this method option."
235
- end
236
-
237
233
  unless values.is_a? Array
238
234
  raise ValidationInvalidArgumentError, values
239
235
  end
@@ -242,14 +238,15 @@ module DSLCompose
242
238
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
243
239
  end
244
240
 
245
- @in_validation = InValidation.new values
241
+ # if this validation has already been applied, then add the values to the existing validation
242
+ if @in_validation
243
+ @in_validation.add_values values
244
+ else
245
+ @in_validation = InValidation.new values
246
+ end
246
247
  end
247
248
 
248
249
  def validate_not_in values
249
- if @not_in_validation
250
- raise ValidationAlreadyExistsError, "The validation `not_in` has already been applied to this method option."
251
- end
252
-
253
250
  unless values.is_a? Array
254
251
  raise ValidationInvalidArgumentError, values
255
252
  end
@@ -258,14 +255,15 @@ module DSLCompose
258
255
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
259
256
  end
260
257
 
261
- @not_in_validation = NotInValidation.new values
258
+ # if this validation has already been applied, then add the values to the existing validation
259
+ if @not_in_validation
260
+ @not_in_validation.add_values values
261
+ else
262
+ @not_in_validation = NotInValidation.new values
263
+ end
262
264
  end
263
265
 
264
266
  def validate_end_with value
265
- if @end_with_validation
266
- raise ValidationAlreadyExistsError, "The validation `end_with` has already been applied to this method option."
267
- end
268
-
269
267
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
270
268
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
271
269
  end
@@ -274,14 +272,15 @@ module DSLCompose
274
272
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
275
273
  end
276
274
 
277
- @end_with_validation = EndWithValidation.new value
275
+ # if this validation has already been applied, then add the values to the existing validation
276
+ if @end_with_validation
277
+ @end_with_validation.add_values value
278
+ else
279
+ @end_with_validation = EndWithValidation.new value
280
+ end
278
281
  end
279
282
 
280
283
  def validate_not_end_with value
281
- if @not_end_with_validation
282
- raise ValidationAlreadyExistsError, "The validation `not_end_with` has already been applied to this method option."
283
- end
284
-
285
284
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
286
285
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
287
286
  end
@@ -290,14 +289,15 @@ module DSLCompose
290
289
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
291
290
  end
292
291
 
293
- @not_end_with_validation = NotEndWithValidation.new value
292
+ # if this validation has already been applied, then add the values to the existing validation
293
+ if @not_end_with_validation
294
+ @not_end_with_validation.add_values value
295
+ else
296
+ @not_end_with_validation = NotEndWithValidation.new value
297
+ end
294
298
  end
295
299
 
296
300
  def validate_start_with value
297
- if @start_with_validation
298
- raise ValidationAlreadyExistsError, "The validation `start_with` has already been applied to this method option."
299
- end
300
-
301
301
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
302
302
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
303
303
  end
@@ -306,14 +306,15 @@ module DSLCompose
306
306
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
307
307
  end
308
308
 
309
- @start_with_validation = StartWithValidation.new value
309
+ # if this validation has already been applied, then add the values to the existing validation
310
+ if @start_with_validation
311
+ @start_with_validation.add_values value
312
+ else
313
+ @start_with_validation = StartWithValidation.new value
314
+ end
310
315
  end
311
316
 
312
317
  def validate_not_start_with value
313
- if @not_start_with_validation
314
- raise ValidationAlreadyExistsError, "The validation `not_start_with` has already been applied to this method option."
315
- end
316
-
317
318
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
318
319
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
319
320
  end
@@ -322,7 +323,12 @@ module DSLCompose
322
323
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
323
324
  end
324
325
 
325
- @not_start_with_validation = NotStartWithValidation.new value
326
+ # if this validation has already been applied, then add the values to the existing validation
327
+ if @not_start_with_validation
328
+ @not_start_with_validation.add_values value
329
+ else
330
+ @not_start_with_validation = NotStartWithValidation.new value
331
+ end
326
332
  end
327
333
 
328
334
  def validate_length maximum: nil, minimum: nil, is: nil
@@ -67,9 +67,14 @@ module DSLCompose
67
67
  # us to use keyword arguments to force a naming convention on these arguments
68
68
  # and to validate their use
69
69
  args = {}
70
+ # the dsl name (if it's requested)
70
71
  if BlockArguments.accepts_argument?(:dsl_name, &block)
71
72
  args[:dsl_name] = dsl_execution.dsl.name
72
73
  end
74
+ # an ExecutionReader object to access the exections methods (if it's requested)
75
+ if BlockArguments.accepts_argument?(:reader, &block)
76
+ args[:reader] = Reader::ExecutionReader.new(dsl_execution)
77
+ end
73
78
  # add any arguments that were provided to the DSL
74
79
  dsl_execution.arguments.arguments.each do |name, value|
75
80
  if BlockArguments.accepts_argument?(name, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.3.0"
4
+ VERSION = "2.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsl_compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-28 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper