dsl_compose 2.13.0 → 2.14.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c143f5741011efd1d4311e4b2b5beab52fb75600f0c7f492fdb199cc3221c502
4
- data.tar.gz: '09a0982fa552f3e36a1005e4b345eaf5294bc3b62c10c41eebb6dbdf42e3a102'
3
+ metadata.gz: 952d89e2f9b95412aec641b8faa5219512290924b02923819ca3438f8d6d1500
4
+ data.tar.gz: 3f66573596355a16a9477bd6844d552691ea9dded5525335de8ae4b1ca114cea
5
5
  SHA512:
6
- metadata.gz: 45988d0bbd27cbc1ee285608a795d1cdc95dccf4bce14ccdd76ea0aad26daec4345262c140f73a4059becbe4148aef9548b5b8f127585557ad90b974c9b0807b
7
- data.tar.gz: e889b48f585730f5a8a05349e8c90e527885e5393512ecea5568feab6c71e0a82ce9e5b7b417af6d7bcbb4a35f9459a4537b0bbb337e5825bc1e72833cef4edf
6
+ metadata.gz: cc1ed1223977ff6acfa4eb6827180673f69f91449ce060f8a1c99e6756e459f78c22261c46bfcf9359e7ac2fc6ea4aa3ba44f9ed839462e04b7518c3a419e928
7
+ data.tar.gz: af5c4e85b2d3368a57610af4ef4b580651e12b32896dcd61d270f5c2d1ebdcda2acf4341a83497f965c695ace817d1d46d827b3da5696f306bf2febf9e8ff04e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.14.0](https://github.com/craigulliott/dsl_compose/compare/v2.13.1...v2.14.0) (2023-09-06)
4
+
5
+
6
+ ### Features
7
+
8
+ * adding start_with/end_with and format validators to classes ([d390d15](https://github.com/craigulliott/dsl_compose/commit/d390d15bf2ebec2340815ff0a372a938072efd0e))
9
+
10
+ ## [2.13.1](https://github.com/craigulliott/dsl_compose/compare/v2.13.0...v2.13.1) (2023-09-05)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * fixed a nil value in error message caused by overwriting method argument ([dd7848b](https://github.com/craigulliott/dsl_compose/commit/dd7848b3861bff6176c8326f6784fb29f1ba2fdd))
16
+
3
17
  ## [2.13.0](https://github.com/craigulliott/dsl_compose/compare/v2.12.0...v2.13.0) (2023-09-04)
4
18
 
5
19
 
data/README.md CHANGED
@@ -597,16 +597,16 @@ The following validations can be added to the arguments of your DSL methods. Val
597
597
  validate_in ["cat", "dog"]
598
598
 
599
599
  # The argument must start with the following string.
600
- validate_start_with [:foo_]
600
+ validate_start_with ["foo_"]
601
601
 
602
602
  # The argument must not start with the following string.
603
- validate_not_start_with [:foo_]
603
+ validate_not_start_with ["foo_"]
604
604
 
605
605
  # The argument must end with the following string.
606
- validate_end_with [:_foo]
606
+ validate_end_with ["_foo"]
607
607
 
608
608
  # The argument must not end with the following string.
609
- validate_not_end_with [:_foo]
609
+ validate_not_end_with ["_foo"]
610
610
 
611
611
  # The argument must match the provided regex.
612
612
  validate_format /\A[A-Z][a-z]+\Z/
@@ -692,7 +692,20 @@ The following validations can be added to the arguments of your DSL methods. Val
692
692
 
693
693
  requires :my_first_argument, :class do
694
694
 
695
- # There are no validations for :class types
695
+ # The class name must start with the following string.
696
+ validate_start_with ["foo_"]
697
+
698
+ # The class name must not start with the following string.
699
+ validate_not_start_with ["foo_"]
700
+
701
+ # The class name must end with the following string.
702
+ validate_end_with ["_foo"]
703
+
704
+ # The class name must not end with the following string.
705
+ validate_not_end_with ["_foo"]
706
+
707
+ # The class name must match the provided regex.
708
+ validate_format /\A[A-Z][a-z]+\Z/
696
709
 
697
710
  end
698
711
 
@@ -5,6 +5,8 @@ module DSLCompose
5
5
  class UnexpectedClassNameError < StandardError
6
6
  end
7
7
 
8
+ attr_reader :class_name
9
+
8
10
  def initialize class_name
9
11
  unless class_name.is_a? String
10
12
  raise UnexpectedClassNameError, "expected `#{class_name}` to be a String"
@@ -17,19 +17,19 @@ module DSLCompose
17
17
  end
18
18
 
19
19
  def add_values values
20
- # if the provided values is a symbol, then convert it to an array
21
- if values.is_a? Symbol
20
+ # if the provided values is a single item then convert it to an array
21
+ if values.is_a?(Symbol) || values.is_a?(String)
22
22
  values = [values]
23
23
  end
24
24
 
25
25
  # assert that the provided values is an array
26
26
  unless values.is_a? Array
27
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
27
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
28
28
  end
29
29
 
30
- # assert that the provided values is an array of symbols
31
- unless values.all? { |value| value.is_a? Symbol }
32
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
30
+ # assert that the provided values is an array of symbols/strings
31
+ unless values.all? { |value| value.is_a? Symbol } || values.all? { |value| value.is_a? String }
32
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
33
33
  end
34
34
 
35
35
  @values += values
@@ -17,19 +17,19 @@ module DSLCompose
17
17
  end
18
18
 
19
19
  def add_values values
20
- # if the provided values is a symbol, then convert it to an array
21
- if values.is_a? Symbol
20
+ # if the provided values is a single item then convert it to an array
21
+ if values.is_a?(Symbol) || values.is_a?(String)
22
22
  values = [values]
23
23
  end
24
24
 
25
25
  # assert that the provided values is an array
26
26
  unless values.is_a? Array
27
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
27
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
28
28
  end
29
29
 
30
- # assert that the provided values is an array of symbols
31
- unless values.all? { |value| value.is_a? Symbol }
32
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
30
+ # assert that the provided values is an array of symbols/strings
31
+ unless values.all? { |value| value.is_a? Symbol } || values.all? { |value| value.is_a? String }
32
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
33
33
  end
34
34
 
35
35
  @values += values
@@ -17,19 +17,19 @@ module DSLCompose
17
17
  end
18
18
 
19
19
  def add_values values
20
- # if the provided values is a symbol, then convert it to an array
21
- if values.is_a? Symbol
20
+ # if the provided values is a single item then convert it to an array
21
+ if values.is_a?(Symbol) || values.is_a?(String)
22
22
  values = [values]
23
23
  end
24
24
 
25
25
  # assert that the provided values is an array
26
26
  unless values.is_a? Array
27
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
27
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
28
28
  end
29
29
 
30
- # assert that the provided values is an array of symbols
31
- unless values.all? { |value| value.is_a? Symbol }
32
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
30
+ # assert that the provided values is an array of symbols/strings
31
+ unless values.all? { |value| value.is_a? Symbol } || values.all? { |value| value.is_a? String }
32
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
33
33
  end
34
34
 
35
35
  @values += values
@@ -17,19 +17,19 @@ module DSLCompose
17
17
  end
18
18
 
19
19
  def add_values values
20
- # if the provided values is a symbol, then convert it to an array
21
- if values.is_a? Symbol
20
+ # if the provided values is a single item then convert it to an array
21
+ if values.is_a?(Symbol) || values.is_a?(String)
22
22
  values = [values]
23
23
  end
24
24
 
25
25
  # assert that the provided values is an array
26
26
  unless values.is_a? Array
27
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
27
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
28
28
  end
29
29
 
30
- # assert that the provided values is an array of symbols
31
- unless values.all? { |value| value.is_a? Symbol }
32
- raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
30
+ # assert that the provided values is an array of symbols/strings
31
+ unless values.all? { |value| value.is_a? Symbol } || values.all? { |value| value.is_a? String }
32
+ raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
33
33
  end
34
34
 
35
35
  @values += values
@@ -225,7 +225,7 @@ module DSLCompose
225
225
  raise ValidationInvalidArgumentError, regexp
226
226
  end
227
227
 
228
- unless @type == :string || @type == :symbol
228
+ unless @type == :string || @type == :symbol || @type == :class
229
229
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
230
230
  end
231
231
  @format_validation = FormatValidation.new regexp
@@ -278,11 +278,11 @@ module DSLCompose
278
278
  end
279
279
 
280
280
  def validate_end_with value
281
- unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
282
- raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
281
+ unless value.is_a?(Symbol) || value.is_a?(String) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) || (value.is_a?(Array) && value.all? { |value| value.is_a? String })
282
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
283
283
  end
284
284
 
285
- unless @type == :string || @type == :symbol
285
+ unless @type == :string || @type == :symbol || @type == :class
286
286
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
287
287
  end
288
288
 
@@ -295,11 +295,11 @@ module DSLCompose
295
295
  end
296
296
 
297
297
  def validate_not_end_with value
298
- unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
299
- raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
298
+ unless value.is_a?(Symbol) || value.is_a?(String) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) || (value.is_a?(Array) && value.all? { |value| value.is_a? String })
299
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
300
300
  end
301
301
 
302
- unless @type == :string || @type == :symbol
302
+ unless @type == :string || @type == :symbol || @type == :class
303
303
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
304
304
  end
305
305
 
@@ -312,11 +312,11 @@ module DSLCompose
312
312
  end
313
313
 
314
314
  def validate_start_with value
315
- unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
316
- raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
315
+ unless value.is_a?(Symbol) || value.is_a?(String) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) || (value.is_a?(Array) && value.all? { |value| value.is_a? String })
316
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
317
317
  end
318
318
 
319
- unless @type == :string || @type == :symbol
319
+ unless @type == :string || @type == :symbol || @type == :class
320
320
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
321
321
  end
322
322
 
@@ -329,11 +329,11 @@ module DSLCompose
329
329
  end
330
330
 
331
331
  def validate_not_start_with value
332
- unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
333
- raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
332
+ unless value.is_a?(Symbol) || value.is_a?(String) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol }) || (value.is_a?(Array) && value.all? { |value| value.is_a? String })
333
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
334
334
  end
335
335
 
336
- unless @type == :string || @type == :symbol
336
+ unless @type == :string || @type == :symbol || @type == :class
337
337
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
338
338
  end
339
339
 
@@ -421,8 +421,11 @@ module DSLCompose
421
421
 
422
422
  # returns true if every provided class validation also returns true
423
423
  def validate_class! value
424
- # there are no class validations
425
- true
424
+ (format_validation.nil? || format_validation.validate!(value.class_name)) &&
425
+ (end_with_validation.nil? || end_with_validation.validate!(value.class_name)) &&
426
+ (not_end_with_validation.nil? || not_end_with_validation.validate!(value.class_name)) &&
427
+ (start_with_validation.nil? || start_with_validation.validate!(value.class_name)) &&
428
+ (not_start_with_validation.nil? || not_start_with_validation.validate!(value.class_name))
426
429
  end
427
430
 
428
431
  # returns true if every provided object validation also returns true
@@ -24,24 +24,25 @@ module DSLCompose
24
24
  # Move up through this classes ancestors until we find the class which defined
25
25
  # the DSL with the provided name. When we reach the top of the ancestor chain we
26
26
  # exit the loop.
27
- while klass
27
+ k = klass
28
+ while k
28
29
  # if we find a DSL with this name, then store a reference to the DSL and the
29
30
  # ancestor class where it was defined
30
- if DSLs.class_dsl_exists?(klass, dsl_name)
31
- @dsl = DSLs.class_dsl(klass, dsl_name)
32
- @dsl_defining_class = klass
31
+ if DSLs.class_dsl_exists?(k, dsl_name)
32
+ @dsl = DSLs.class_dsl(k, dsl_name)
33
+ @dsl_defining_class = k
33
34
  # stop once we find the DSL
34
35
  break
35
36
  end
36
37
 
37
38
  # the DSL was not found here, so traverse up the provided classes hierachy
38
39
  # and keep looking for where this DSL was initially defined
39
- klass = klass.superclass
40
+ k = k.superclass
40
41
  end
41
42
 
42
43
  # if no DSL was found, then raise an error
43
44
  if @dsl.nil? && @dsl_defining_class.nil?
44
- raise DSLNotFound, "No DSL named `#{dsl_name}` was found for class `#{klass}`"
45
+ raise DSLNotFound, "No DSL named `#{dsl_name}` was found for class `#{@klass}`"
45
46
  end
46
47
  end
47
48
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.13.0"
4
+ VERSION = "2.14.0"
5
5
  end
@@ -6,7 +6,7 @@ module DSLCompose
6
6
  class EndWithValidation
7
7
  @values: Array[Symbol]
8
8
 
9
- def initialize: (Symbol | Array[Symbol]) -> void
9
+ def initialize: (Symbol | Array[Symbol] | String | Array[String]) -> void
10
10
  def validate!: (Symbol | String value) -> true
11
11
 
12
12
  class InvalidValueError < StandardError
@@ -19,10 +19,10 @@ module DSLCompose
19
19
  def validate_length: (?minimum: Numeric?, ?maximum: Numeric?, ?is: Numeric?) -> void
20
20
  def validate_not_in: ([Numeric | Symbol | String] values) -> void
21
21
  def validate_in: ([Numeric | Symbol | String] values) -> void
22
- def validate_end_with: (Symbol | Array[Symbol] value) -> void
23
- def validate_not_end_with: (Symbol | Array[Symbol] value) -> void
24
- def validate_start_with: (Symbol | Array[Symbol] value) -> void
25
- def validate_not_start_with: (Symbol | Array[Symbol] value) -> void
22
+ def validate_end_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
23
+ def validate_not_end_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
24
+ def validate_start_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
25
+ def validate_not_start_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
26
26
  def validate_format: (Regexp regex) -> void
27
27
  def validate_is_a: (String class_name) -> void
28
28
  end
@@ -6,7 +6,7 @@ module DSLCompose
6
6
  class NotEndWithValidation
7
7
  @values: Array[Symbol]
8
8
 
9
- def initialize: (Symbol | Array[Symbol]) -> void
9
+ def initialize: (Symbol | Array[Symbol] | String | Array[String]) -> void
10
10
  def validate!: (Symbol | String value) -> true
11
11
 
12
12
  class InvalidValueError < StandardError
@@ -6,7 +6,7 @@ module DSLCompose
6
6
  class NotStartWithValidation
7
7
  @values: Array[Symbol]
8
8
 
9
- def initialize: (Symbol | Array[Symbol]) -> void
9
+ def initialize: (Symbol | Array[Symbol] | String | Array[String]) -> void
10
10
  def validate!: (Symbol | String value) -> true
11
11
 
12
12
  class InvalidValueError < StandardError
@@ -6,7 +6,7 @@ module DSLCompose
6
6
  class StartWithValidation
7
7
  @values: Array[Symbol]
8
8
 
9
- def initialize: (Symbol | Array[Symbol]) -> void
9
+ def initialize: (Symbol | Array[Symbol] | String | Array[String]) -> void
10
10
  def validate!: (Symbol | String value) -> true
11
11
 
12
12
  class InvalidValueError < StandardError
@@ -42,10 +42,10 @@ module DSLCompose
42
42
  def validate_equal_to: (Numeric | Symbol | String value) -> void
43
43
  def validate_in: (Array[Numeric | Symbol | String] values) -> void
44
44
  def validate_not_in: (Array[Numeric | Symbol | String] values) -> void
45
- def validate_end_with: (Symbol | Array[Symbol] value) -> void
46
- def validate_not_end_with: (Symbol | Array[Symbol] value) -> void
47
- def validate_start_with: (Symbol | Array[Symbol] value) -> void
48
- def validate_not_start_with: (Symbol | Array[Symbol] value) -> void
45
+ def validate_end_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
46
+ def validate_not_end_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
47
+ def validate_start_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
48
+ def validate_not_start_with: (Symbol | Array[Symbol] | String | Array[String] value) -> void
49
49
  def validate_length: (?maximum: nil | Numeric, ?minimum: nil | Numeric, ?is: nil | Numeric) -> void
50
50
  def validate_is_a: (String class_name) -> void
51
51
 
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.13.0
4
+ version: 2.14.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-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper