dsl_compose 1.7.0 → 1.8.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: 461fe3b90a0a36703aee0be51b3594472d2fc55ff1eab2b6b5bfabd851446d09
4
- data.tar.gz: 65ba43be5dfcefbaf5588744b66fcd73a8266abbea65bcb59699132c43ed47a7
3
+ metadata.gz: f39f962fc5991e68164ab544ca3cb85b7f538296d393f360fdda683956c883bd
4
+ data.tar.gz: d68a46d791c33ac1ed435d9be92490ebbd76b053f13d2ef5a17247caf245b148
5
5
  SHA512:
6
- metadata.gz: 9d2b86c2398b49217ba29152f68f6666e0bcbe926d4adadaac29b4f4a3d8500b120192c469c4fa25f68b68c58e73782459356a7845bcabb0237076521e4e0f37
7
- data.tar.gz: 4f58959006d911cb13d75ccddc1871416736236d0e278844f6beb1c22a546d2e8d3620230931a2108c8949ad346a65ce27f3ae437fd8d55e5563603ad8421d24
6
+ metadata.gz: 97b3fdcdd3b2ded2028155a9a767fb9cacf8a0e39b00a3cf8e203290d78a7bdbce9119b0b2b856b82afb61c209e24025c9e94991dfa5abe7383f55efc69446e4
7
+ data.tar.gz: 38d4eda779bb41af8300ce7d266307eb8fa58529bca51d9c9dcf1589ed1b11f535d4a0746ea359c18f56ca5aae30a13655d987bc0f3de06bf2bdc6f560701f82
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## [1.7.0](https://github.com/craigulliott/dsl_compose/compare/v1.6.0...v1.7.0) (2023-07-07)
4
11
 
5
12
 
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,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
@@ -14,6 +14,7 @@ module DSLCompose
14
14
 
15
15
  def validate! value
16
16
  raise ValidationFailedError, "The argument is invalid. Expected #{@value} but received #{value}" unless value == @value
17
+ true
17
18
  end
18
19
  end
19
20
  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
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected greater than or equal to #{@value} but received #{value}" unless value >= @value
24
+ true
24
25
  end
25
26
  end
26
27
  end
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected greater than #{@value} but received #{value}" unless value > @value
24
+ true
24
25
  end
25
26
  end
26
27
  end
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected in #{@values} but received #{value}" unless @values.include? value
24
+ true
24
25
  end
25
26
  end
26
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
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected less than or equal to #{@value} but received #{value}" unless value <= @value
24
+ true
24
25
  end
25
26
  end
26
27
  end
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected less than #{@value} but received #{value}" unless value < @value
24
+ true
24
25
  end
25
26
  end
26
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
@@ -21,6 +21,7 @@ module DSLCompose
21
21
 
22
22
  def validate! value
23
23
  raise ValidationFailedError, "The argument is invalid. Expected not in #{@values} but received #{value}" if @values.include?(value)
24
+ true
24
25
  end
25
26
  end
26
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
@@ -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? String
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? String
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? String
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? String
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "1.7.0"
4
+ VERSION = "1.8.0"
5
5
  end
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.7.0
4
+ version: 1.8.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-07 00:00:00.000000000 Z
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