dsl_compose 2.13.1 → 2.14.1

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: 117789e8395652f4823ad048b258d2a683b65328d5817788b9d3d3d7bc377c8b
4
- data.tar.gz: d4ad4b7a66de0cfd143006e4c9984bef0ce1c29e6e18b86a0621810cb2d11edb
3
+ metadata.gz: 7dae8c4f74589b916fbfc6f67f181d58b6e2044aa9eed65a4e26e2e2d05b1fbc
4
+ data.tar.gz: c9663b356014625a531f22fc093b3f0c0117be81b49a6157b9068b196c4db2dc
5
5
  SHA512:
6
- metadata.gz: dbcf361a908dcd619664f12e50299f80092d5e2f4e8efb4f53320b2d13c3ca30ef334e429fe1a977fb899c0878f2dd26a30d9b067b74da22198eb2372984d2ad
7
- data.tar.gz: 9e932a4d10693634bc25532d9d625ad1939f58c975bf90a0f4a0f1714586bdce5dc1650cf48cbfaa0655c56fbaa341fd27731953e4e3fe74fbefd63619fac6ad
6
+ metadata.gz: 7e6ccea99702dc7e02344b4dfe169433b61a363e6ea0d3c3bf4abae0c531c240e4a37a68e384e5d9b7b96a63438e768b3b8beb2ae37fc657ffd141ff80e707b1
7
+ data.tar.gz: 2eec3427dc377746dce4e708a6c2c1d12bcb6ec94637ae9f425810d7b5665b90e51178b62ff0ce6d0f22409697c7611e3c363bb636d4f8f9a88ae990c39ddfcb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.14.1](https://github.com/craigulliott/dsl_compose/compare/v2.14.0...v2.14.1) (2023-09-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * freezing dsl arguments so that other parts of the code can't change the underlying dsl configuration ([d3373d4](https://github.com/craigulliott/dsl_compose/commit/d3373d494b292241bc17f38e565a2434e5e0d187))
9
+
10
+ ## [2.14.0](https://github.com/craigulliott/dsl_compose/compare/v2.13.1...v2.14.0) (2023-09-06)
11
+
12
+
13
+ ### Features
14
+
15
+ * adding start_with/end_with and format validators to classes ([d390d15](https://github.com/craigulliott/dsl_compose/commit/d390d15bf2ebec2340815ff0a372a938072efd0e))
16
+
3
17
  ## [2.13.1](https://github.com/craigulliott/dsl_compose/compare/v2.13.0...v2.13.1) (2023-09-05)
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,14 @@ 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
+ valid_type = value.is_a?(Symbol) || value.is_a?(String)
282
+ valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
283
+ valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String })
284
+ unless valid_type || valid_array_of_symbols || valid_array_of_strings
285
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
283
286
  end
284
287
 
285
- unless @type == :string || @type == :symbol
288
+ unless @type == :string || @type == :symbol || @type == :class
286
289
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
287
290
  end
288
291
 
@@ -295,11 +298,14 @@ module DSLCompose
295
298
  end
296
299
 
297
300
  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"
301
+ valid_type = value.is_a?(Symbol) || value.is_a?(String)
302
+ valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
303
+ valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String })
304
+ unless valid_type || valid_array_of_symbols || valid_array_of_strings
305
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
300
306
  end
301
307
 
302
- unless @type == :string || @type == :symbol
308
+ unless @type == :string || @type == :symbol || @type == :class
303
309
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
304
310
  end
305
311
 
@@ -312,11 +318,14 @@ module DSLCompose
312
318
  end
313
319
 
314
320
  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"
321
+ valid_type = value.is_a?(Symbol) || value.is_a?(String)
322
+ valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
323
+ valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String })
324
+ unless valid_type || valid_array_of_symbols || valid_array_of_strings
325
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
317
326
  end
318
327
 
319
- unless @type == :string || @type == :symbol
328
+ unless @type == :string || @type == :symbol || @type == :class
320
329
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
321
330
  end
322
331
 
@@ -329,11 +338,14 @@ module DSLCompose
329
338
  end
330
339
 
331
340
  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"
341
+ valid_type = value.is_a?(Symbol) || value.is_a?(String)
342
+ valid_array_of_symbols = (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
343
+ valid_array_of_strings = (value.is_a?(Array) && value.all? { |value| value.is_a? String })
344
+ unless valid_type || valid_array_of_symbols || valid_array_of_strings
345
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
334
346
  end
335
347
 
336
- unless @type == :string || @type == :symbol
348
+ unless @type == :string || @type == :symbol || @type == :class
337
349
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
338
350
  end
339
351
 
@@ -421,8 +433,11 @@ module DSLCompose
421
433
 
422
434
  # returns true if every provided class validation also returns true
423
435
  def validate_class! value
424
- # there are no class validations
425
- true
436
+ (format_validation.nil? || format_validation.validate!(value.class_name)) &&
437
+ (end_with_validation.nil? || end_with_validation.validate!(value.class_name)) &&
438
+ (not_end_with_validation.nil? || not_end_with_validation.validate!(value.class_name)) &&
439
+ (start_with_validation.nil? || start_with_validation.validate!(value.class_name)) &&
440
+ (not_start_with_validation.nil? || not_start_with_validation.validate!(value.class_name))
426
441
  end
427
442
 
428
443
  # returns true if every provided object validation also returns true
@@ -101,7 +101,7 @@ module DSLCompose
101
101
  ClassCoerce.new optional_arg[optional_argument_name]
102
102
  end
103
103
  else
104
- optional_arg[optional_argument_name]
104
+ optional_arg[optional_argument_name].freeze
105
105
  end
106
106
 
107
107
  if optional_arg_value.is_a?(Array) && !optional_argument.array
@@ -191,7 +191,7 @@ module DSLCompose
191
191
  ClassCoerce.new required_args[i]
192
192
  end
193
193
  else
194
- required_args[i]
194
+ required_args[i].freeze
195
195
  end
196
196
 
197
197
  if required_arg_value.is_a?(Array) && !required_argument.array
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.13.1"
4
+ VERSION = "2.14.1"
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.1
4
+ version: 2.14.1
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-05 00:00:00.000000000 Z
11
+ date: 2023-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper