dsl_compose 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51a691703918ebafb30bb7c158e627e6a02597e9171e38d1b87cd4cd066d825d
4
- data.tar.gz: 4e750c6839f7946299f13e81b8af0a7ca94e8d852d7a418f8be97658a0ba67a8
3
+ metadata.gz: f39f962fc5991e68164ab544ca3cb85b7f538296d393f360fdda683956c883bd
4
+ data.tar.gz: d68a46d791c33ac1ed435d9be92490ebbd76b053f13d2ef5a17247caf245b148
5
5
  SHA512:
6
- metadata.gz: aa82b56b1c7b6cfcbf4b0116c34b4084f5873cd5d957ceb615b16ab4b36f44a6d3da1ffea8a8ef779b837322d0622254e8688fa4fecffdcb6a011a531aa31106
7
- data.tar.gz: b1d02bc6e922d35aeee52095bfd3847d5ae347ef56e6278a4f90bb4c76666e0829dad6638956f96a555400a129160f5431d197b264dc1103532c2a1b6df14de2
6
+ metadata.gz: 97b3fdcdd3b2ded2028155a9a767fb9cacf8a0e39b00a3cf8e203290d78a7bdbce9119b0b2b856b82afb61c209e24025c9e94991dfa5abe7383f55efc69446e4
7
+ data.tar.gz: 38d4eda779bb41af8300ce7d266307eb8fa58529bca51d9c9dcf1589ed1b11f535d4a0746ea359c18f56ca5aae30a13655d987bc0f3de06bf2bdc6f560701f82
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.8.0](https://github.com/craigulliott/dsl_compose/compare/v1.7.0...v1.8.0) (2023-07-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * adding start_with, not_start_with, end_with and not_end_with ar… ([#21](https://github.com/craigulliott/dsl_compose/issues/21)) ([ea2f213](https://github.com/craigulliott/dsl_compose/commit/ea2f2130c1b9a856e89cbf9b4f09c0c3c739d3de))
9
+
10
+ ## [1.7.0](https://github.com/craigulliott/dsl_compose/compare/v1.6.0...v1.7.0) (2023-07-07)
11
+
12
+
13
+ ### Features
14
+
15
+ * better error messages ([#19](https://github.com/craigulliott/dsl_compose/issues/19)) ([a9afa6c](https://github.com/craigulliott/dsl_compose/commit/a9afa6cb1b7482d0d7a646b6872ca5e969393eb7))
16
+
3
17
  ## [1.6.0](https://github.com/craigulliott/dsl_compose/compare/v1.5.0...v1.6.0) (2023-07-07)
4
18
 
5
19
 
data/README.md CHANGED
@@ -292,6 +292,18 @@ The following validations can be added to the arguments of your DSL methods. Val
292
292
  # The argument must be one of the provided values.
293
293
  validate_in ["cat", "dog"]
294
294
 
295
+ # The argument must start with the following string.
296
+ validate_start_with ["foo_"]
297
+
298
+ # The argument must not start with the following string.
299
+ validate_not_start_with ["foo_"]
300
+
301
+ # The argument must end with the following string.
302
+ validate_end_with ["_foo"]
303
+
304
+ # The argument must not end with the following string.
305
+ validate_not_end_with ["_foo"]
306
+
295
307
  # The argument must match the provided regex.
296
308
  validate_format /\A[A-Z][a-z]+\Z/
297
309
 
@@ -327,6 +339,18 @@ The following validations can be added to the arguments of your DSL methods. Val
327
339
  # The argument must be one of the provided values.
328
340
  validate_in [:cat, :dog]
329
341
 
342
+ # The argument must start with the following string.
343
+ validate_start_with ["foo_"]
344
+
345
+ # The argument must not start with the following string.
346
+ validate_not_start_with ["foo_"]
347
+
348
+ # The argument must end with the following string.
349
+ validate_end_with ["_foo"]
350
+
351
+ # The argument must not end with the following string.
352
+ validate_not_end_with ["_foo"]
353
+
330
354
  # The argument must match the provided regex.
331
355
  validate_format /\A[A-Z][a-z]+\Z/
332
356
 
@@ -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
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSLCompose
4
+ class DSL
5
+ class Arguments
6
+ class Argument
7
+ class EndWithValidation
8
+ class InvalidValueError < StandardError
9
+ end
10
+
11
+ class ValidationFailedError < StandardError
12
+ end
13
+
14
+ def initialize value
15
+ unless value.is_a?(String)
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type String"
17
+ end
18
+
19
+ @value = value
20
+ end
21
+
22
+ def validate! value
23
+ raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to end with `#{@value}`" unless value.end_with? @value
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -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,8 @@ 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
17
+ true
20
18
  end
21
19
  end
22
20
  end
@@ -6,17 +6,19 @@ 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
12
+ unless regex.is_a?(Regexp)
13
+ raise InvalidValueError, "The value `#{regex}` provided to this validator must be of type Regexp"
14
+ end
15
+
15
16
  @regex = regex
16
17
  end
17
18
 
18
19
  def validate! value
19
- raise ValidationFailedError if @regex.match(value).nil?
20
+ raise ValidationFailedError, "The argument is invalid. Expected format #{@regex} but received #{value}" if @regex.match(value).nil?
21
+ true
20
22
  end
21
23
  end
22
24
  end
@@ -6,27 +6,22 @@ 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
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -6,27 +6,22 @@ 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
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -6,27 +6,22 @@ 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
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -75,6 +75,26 @@ module DSLCompose
75
75
  @argument.validate_in values
76
76
  end
77
77
 
78
+ # adds an end_with validator to the argument
79
+ def validate_end_with value
80
+ @argument.validate_end_with value
81
+ end
82
+
83
+ # adds a not_end_with validator to the argument
84
+ def validate_not_end_with value
85
+ @argument.validate_not_end_with value
86
+ end
87
+
88
+ # adds a start_with validator to the argument
89
+ def validate_start_with value
90
+ @argument.validate_start_with value
91
+ end
92
+
93
+ # adds a not_start_with validator to the argument
94
+ def validate_not_start_with value
95
+ @argument.validate_not_start_with value
96
+ end
97
+
78
98
  # adds a format validator to the argument
79
99
  def validate_format regexp
80
100
  @argument.validate_format regexp
@@ -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,22 @@ 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
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -6,27 +6,22 @@ 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
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSLCompose
4
+ class DSL
5
+ class Arguments
6
+ class Argument
7
+ class NotEndWithValidation
8
+ class InvalidValueError < StandardError
9
+ end
10
+
11
+ class ValidationFailedError < StandardError
12
+ end
13
+
14
+ def initialize value
15
+ unless value.is_a?(String)
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type String"
17
+ end
18
+
19
+ @value = value
20
+ end
21
+
22
+ def validate! value
23
+ raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to not end with `#{@value}`" if value.end_with? @value
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -6,27 +6,22 @@ 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)
24
+ true
30
25
  end
31
26
  end
32
27
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSLCompose
4
+ class DSL
5
+ class Arguments
6
+ class Argument
7
+ class NotStartWithValidation
8
+ class InvalidValueError < StandardError
9
+ end
10
+
11
+ class ValidationFailedError < StandardError
12
+ end
13
+
14
+ def initialize value
15
+ unless value.is_a?(String)
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type String"
17
+ end
18
+
19
+ @value = value
20
+ end
21
+
22
+ def validate! value
23
+ raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to not start with `#{@value}`" if value.start_with? @value
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSLCompose
4
+ class DSL
5
+ class Arguments
6
+ class Argument
7
+ class StartWithValidation
8
+ class InvalidValueError < StandardError
9
+ end
10
+
11
+ class ValidationFailedError < StandardError
12
+ end
13
+
14
+ def initialize value
15
+ unless value.is_a?(String)
16
+ raise InvalidValueError, "The value `#{value}` provided to this validator must be of type String"
17
+ end
18
+
19
+ @value = value
20
+ end
21
+
22
+ def validate! value
23
+ raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to start with `#{@value}`" unless value.start_with? @value
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end