dsl_compose 1.7.0 → 1.9.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +24 -0
- data/lib/dsl_compose/dsl/arguments/argument/end_with_validation.rb +41 -0
- data/lib/dsl_compose/dsl/arguments/argument/equal_to_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/format_validation.rb +5 -0
- data/lib/dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/greater_than_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/in_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/interpreter.rb +20 -0
- data/lib/dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/less_than_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb +41 -0
- data/lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb +1 -0
- data/lib/dsl_compose/dsl/arguments/argument/not_start_with_validation.rb +41 -0
- data/lib/dsl_compose/dsl/arguments/argument/start_with_validation.rb +41 -0
- data/lib/dsl_compose/dsl/arguments/argument.rb +76 -0
- data/lib/dsl_compose/version.rb +1 -1
- data/lib/dsl_compose.rb +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44f916259ac32c44bb38f5c8a423d6e41f9c3b61604715bb1e550b1ab9f5dc64
|
4
|
+
data.tar.gz: 22a2303459feb386ac8fa0995323fa95001d2312e83d90271d0868f66cf69e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcf694293406ec2b317da5a9ea7f9fcfac87efae1ecd8cf481e27325d916b61ffdb23b54909589d01cdbb2e30d1fc612c5f6bd7d6e1618e2db937bf97c43f052
|
7
|
+
data.tar.gz: a50c27fe9ffab7b47326c1e4826983fe0bcec1428fed0f2d5d7e0b54d928e5c592cba2d8973b88f11e08bcc295f50a6def76058de086d97fd14f98273c656019
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.9.0](https://github.com/craigulliott/dsl_compose/compare/v1.8.0...v1.9.0) (2023-07-11)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* start_with, not_start_with, end_with and not_end_with validators now accept an array of values to test against ([#23](https://github.com/craigulliott/dsl_compose/issues/23)) ([cddcb4b](https://github.com/craigulliott/dsl_compose/commit/cddcb4b629499e3af0d71cc27f5c2f1dd8ae76d5))
|
9
|
+
|
10
|
+
## [1.8.0](https://github.com/craigulliott/dsl_compose/compare/v1.7.0...v1.8.0) (2023-07-11)
|
11
|
+
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* 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))
|
16
|
+
|
3
17
|
## [1.7.0](https://github.com/craigulliott/dsl_compose/compare/v1.6.0...v1.7.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
|
|
@@ -0,0 +1,41 @@
|
|
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 values
|
15
|
+
# if the provided values is a symbol, then convert it to an array
|
16
|
+
if values.is_a? Symbol
|
17
|
+
values = [values]
|
18
|
+
end
|
19
|
+
|
20
|
+
# assert that the provided values is an array
|
21
|
+
unless values.is_a? Array
|
22
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
23
|
+
end
|
24
|
+
|
25
|
+
# assert that the provided values is an array of symbols
|
26
|
+
unless values.all? { |value| value.is_a? Symbol }
|
27
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
28
|
+
end
|
29
|
+
|
30
|
+
@values = values
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate! value
|
34
|
+
raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to end with `#{@values}`" unless @values.filter { |v| value.end_with? v.to_s }.any?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -9,11 +9,16 @@ module DSLCompose
|
|
9
9
|
end
|
10
10
|
|
11
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
|
+
|
12
16
|
@regex = regex
|
13
17
|
end
|
14
18
|
|
15
19
|
def validate! value
|
16
20
|
raise ValidationFailedError, "The argument is invalid. Expected format #{@regex} but received #{value}" if @regex.match(value).nil?
|
21
|
+
true
|
17
22
|
end
|
18
23
|
end
|
19
24
|
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
|
@@ -0,0 +1,41 @@
|
|
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 values
|
15
|
+
# if the provided values is a symbol, then convert it to an array
|
16
|
+
if values.is_a? Symbol
|
17
|
+
values = [values]
|
18
|
+
end
|
19
|
+
|
20
|
+
# assert that the provided values is an array
|
21
|
+
unless values.is_a? Array
|
22
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
23
|
+
end
|
24
|
+
|
25
|
+
# assert that the provided values is an array of symbols
|
26
|
+
unless values.all? { |value| value.is_a? Symbol }
|
27
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
28
|
+
end
|
29
|
+
|
30
|
+
@values = values
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate! value
|
34
|
+
raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to not end with `#{@values}`" if @values.filter { |v| value.end_with? v.to_s }.any?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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 values
|
15
|
+
# if the provided values is a symbol, then convert it to an array
|
16
|
+
if values.is_a? Symbol
|
17
|
+
values = [values]
|
18
|
+
end
|
19
|
+
|
20
|
+
# assert that the provided values is an array
|
21
|
+
unless values.is_a? Array
|
22
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
23
|
+
end
|
24
|
+
|
25
|
+
# assert that the provided values is an array of symbols
|
26
|
+
unless values.all? { |value| value.is_a? Symbol }
|
27
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
28
|
+
end
|
29
|
+
|
30
|
+
@values = values
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate! value
|
34
|
+
raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to not start with `#{@values}`" if @values.filter { |v| value.start_with? v.to_s }.any?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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 values
|
15
|
+
# if the provided values is a symbol, then convert it to an array
|
16
|
+
if values.is_a? Symbol
|
17
|
+
values = [values]
|
18
|
+
end
|
19
|
+
|
20
|
+
# assert that the provided values is an array
|
21
|
+
unless values.is_a? Array
|
22
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
23
|
+
end
|
24
|
+
|
25
|
+
# assert that the provided values is an array of symbols
|
26
|
+
unless values.all? { |value| value.is_a? Symbol }
|
27
|
+
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
|
28
|
+
end
|
29
|
+
|
30
|
+
@values = values
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate! value
|
34
|
+
raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to start with `#{@values}`" unless @values.filter { |v| value.start_with? v.to_s }.any?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -56,6 +56,10 @@ module DSLCompose
|
|
56
56
|
attr_reader :equal_to_validation
|
57
57
|
attr_reader :in_validation
|
58
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
|
59
63
|
attr_reader :length_validation
|
60
64
|
|
61
65
|
# Create a new Attribute object.
|
@@ -251,6 +255,70 @@ module DSLCompose
|
|
251
255
|
@not_in_validation = NotInValidation.new values
|
252
256
|
end
|
253
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? Symbol
|
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? Symbol
|
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? Symbol
|
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? Symbol
|
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
|
+
|
254
322
|
def validate_length maximum: nil, minimum: nil, is: nil
|
255
323
|
if @length_validation
|
256
324
|
raise ValidationAlreadyExistsError, "The validation `length` has already been applied to this method option."
|
@@ -282,6 +350,10 @@ module DSLCompose
|
|
282
350
|
(equal_to_validation.nil? || equal_to_validation.validate!(value)) &&
|
283
351
|
(in_validation.nil? || in_validation.validate!(value)) &&
|
284
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)) &&
|
285
357
|
(length_validation.nil? || length_validation.validate!(value))
|
286
358
|
end
|
287
359
|
|
@@ -291,6 +363,10 @@ module DSLCompose
|
|
291
363
|
(equal_to_validation.nil? || equal_to_validation.validate!(value)) &&
|
292
364
|
(in_validation.nil? || in_validation.validate!(value)) &&
|
293
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)) &&
|
294
370
|
(length_validation.nil? || length_validation.validate!(value))
|
295
371
|
end
|
296
372
|
|
data/lib/dsl_compose/version.rb
CHANGED
data/lib/dsl_compose.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "dsl_compose/version"
|
4
4
|
|
5
5
|
require "dsl_compose/dsl/arguments/argument/equal_to_validation"
|
6
|
+
require "dsl_compose/dsl/arguments/argument/end_with_validation"
|
6
7
|
require "dsl_compose/dsl/arguments/argument/format_validation"
|
7
8
|
require "dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation"
|
8
9
|
require "dsl_compose/dsl/arguments/argument/greater_than_validation"
|
@@ -10,7 +11,10 @@ require "dsl_compose/dsl/arguments/argument/in_validation"
|
|
10
11
|
require "dsl_compose/dsl/arguments/argument/length_validation"
|
11
12
|
require "dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation"
|
12
13
|
require "dsl_compose/dsl/arguments/argument/less_than_validation"
|
14
|
+
require "dsl_compose/dsl/arguments/argument/not_end_with_validation"
|
13
15
|
require "dsl_compose/dsl/arguments/argument/not_in_validation"
|
16
|
+
require "dsl_compose/dsl/arguments/argument/not_start_with_validation"
|
17
|
+
require "dsl_compose/dsl/arguments/argument/start_with_validation"
|
14
18
|
|
15
19
|
require "dsl_compose/dsl/arguments/argument/interpreter"
|
16
20
|
require "dsl_compose/dsl/arguments/argument"
|
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: 1.
|
4
|
+
version: 1.9.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-
|
11
|
+
date: 2023-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem to add dynamic DSLs to classes. DSLs are added to classes by
|
14
14
|
including the DSLCompose module, and then calling the add_dsl singleton method within
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/dsl_compose/dsl.rb
|
29
29
|
- lib/dsl_compose/dsl/arguments.rb
|
30
30
|
- lib/dsl_compose/dsl/arguments/argument.rb
|
31
|
+
- lib/dsl_compose/dsl/arguments/argument/end_with_validation.rb
|
31
32
|
- lib/dsl_compose/dsl/arguments/argument/equal_to_validation.rb
|
32
33
|
- lib/dsl_compose/dsl/arguments/argument/format_validation.rb
|
33
34
|
- lib/dsl_compose/dsl/arguments/argument/greater_than_or_equal_to_validation.rb
|
@@ -37,7 +38,10 @@ files:
|
|
37
38
|
- lib/dsl_compose/dsl/arguments/argument/length_validation.rb
|
38
39
|
- lib/dsl_compose/dsl/arguments/argument/less_than_or_equal_to_validation.rb
|
39
40
|
- lib/dsl_compose/dsl/arguments/argument/less_than_validation.rb
|
41
|
+
- lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb
|
40
42
|
- lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb
|
43
|
+
- lib/dsl_compose/dsl/arguments/argument/not_start_with_validation.rb
|
44
|
+
- lib/dsl_compose/dsl/arguments/argument/start_with_validation.rb
|
41
45
|
- lib/dsl_compose/dsl/dsl_method.rb
|
42
46
|
- lib/dsl_compose/dsl/dsl_method/interpreter.rb
|
43
47
|
- lib/dsl_compose/dsl/interpreter.rb
|