dsl_compose 2.4.0 → 2.5.1

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: 43cfe766f3e464ba7f5a22128e7f5155806f92686555aef5f2f06af2b58916af
4
- data.tar.gz: 999dc31a662af4684b2956a50c226aa596b345ece609d2b9ace058eea211f924
3
+ metadata.gz: d558cb69dae4f6a6ea4e6a2fe996a88ea0a94545e94f68c22c0800732d0745da
4
+ data.tar.gz: 9527152eda7312f711c9881fffb26cc2feae295d67be646ace5ce9a20f6dc88b
5
5
  SHA512:
6
- metadata.gz: 78b2add3e95f52ae184abb3d2a30f9218d966a8d44e378b72ea37c5ad2dfd6c3409f7a9cf08e4762d17cf717c2ff35c2f7da4ce5a28d8959eacbcf92c484c0db
7
- data.tar.gz: 7d4e1550f001a40d0665c6258eff2cd16d0052f209b1c6741a3252b0623f698345d8344014555153649dd705077dda8cc39d08531bb95bd5df4611cde257c156
6
+ metadata.gz: 5c60f96f11f85c753138ea3a1f4fefe227fdb7ce48191e6dc204380e603916204e62e398ca0813487ed92f15dea9f38596050e5f91484a9ceab604ef11ff828e
7
+ data.tar.gz: 7eae02a8c4d6fa2e43ab4789ae1399c74e744bbccdfb46e60804f41d7982e11e9187b2f332fe6db53f858b867584f4317b981ca360f982d78fe05346db576f94
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.5.1](https://github.com/craigulliott/dsl_compose/compare/v2.5.0...v2.5.1) (2023-08-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * defaulting optional boolean values to false instead of nil in the parser ([3a4b4d7](https://github.com/craigulliott/dsl_compose/commit/3a4b4d7df315e60dca0e66af37d77b800dc6be2c))
9
+ * stripping white space off descriptions ([93ba9d2](https://github.com/craigulliott/dsl_compose/commit/93ba9d21f57a4f58f70f24a44cd58121741da8d0))
10
+
11
+ ## [2.5.0](https://github.com/craigulliott/dsl_compose/compare/v2.4.0...v2.5.0) (2023-08-01)
12
+
13
+
14
+ ### Features
15
+
16
+ * you can call validators which accept arrays (such as `validate_in`) multiple times and they will be combined ([e1b4411](https://github.com/craigulliott/dsl_compose/commit/e1b441176768726cecd828e303781a57d4e36750))
17
+
3
18
  ## [2.4.0](https://github.com/craigulliott/dsl_compose/compare/v2.3.0...v2.4.0) (2023-07-31)
4
19
 
5
20
 
data/README.md CHANGED
@@ -42,7 +42,7 @@ class Foo
42
42
  define_dsl :your_dsl do
43
43
 
44
44
  # A description of your DSL
45
- description <<-DESCRIPTION
45
+ description <<~DESCRIPTION
46
46
  Add a description of your DSL here, this description will be
47
47
  used when generating the documentation for your DSL.
48
48
 
@@ -191,7 +191,7 @@ class MyClientLibrary
191
191
  description "Configure the settings for MyClientLibrary"
192
192
 
193
193
  add_unique_method :api_key, required: true do
194
- description <<-DESCRIPTION
194
+ description <<~DESCRIPTION
195
195
  Your API key.
196
196
 
197
197
  API keys can be generated from your developer
@@ -247,7 +247,7 @@ class MyParser < DSLCompose::Parser
247
247
  # which extend the provided base class, but do not have their own children) then
248
248
  # use `for_final_children_of` instead of `for_children_of`
249
249
  for_children_of SomeBaseClass do |child_class:|
250
- description <<-DESCRIPTION
250
+ description <<~DESCRIPTION
251
251
  You can optionally provide a description of anything specific that your parser
252
252
  does in this block, this description will be used when generating documentation
253
253
 
@@ -281,7 +281,7 @@ class MyParser < DSLCompose::Parser
281
281
  # which were called within this use of your DSL. There is more documentation about
282
282
  # Reader classes below.
283
283
  for_dsl [:dsl1, :dsl2] do |dsl_name:, a_dsl_argument:, reader:|
284
- description <<-DESCRIPTION
284
+ description <<~DESCRIPTION
285
285
  You can optionally provide a description of anything specific that your parser
286
286
  does in this block, this description will be used when generating documentation.
287
287
 
@@ -308,7 +308,7 @@ class MyParser < DSLCompose::Parser
308
308
  # are provided then the requested dsl argument must be present on all DSLs
309
309
  # otherwise an error will be raised.
310
310
  for_method :some_method_name do |method_name:, a_method_argument:|
311
- description <<-DESCRIPTION
311
+ description <<~DESCRIPTION
312
312
  You can optionally provide a description of anything specific that your parser
313
313
  does in this block, this description will be used when generating documentation.
314
314
 
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,11 +12,16 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  unless values.is_a?(Array)
16
21
  raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
17
22
  end
18
23
 
19
- @values = values
24
+ @values += values
20
25
  end
21
26
 
22
27
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,11 +12,16 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  unless values.is_a?(Array)
16
21
  raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
17
22
  end
18
23
 
19
- @values = values
24
+ @values += values
20
25
  end
21
26
 
22
27
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -12,6 +12,11 @@ module DSLCompose
12
12
  end
13
13
 
14
14
  def initialize values
15
+ @values = []
16
+ add_values values
17
+ end
18
+
19
+ def add_values values
15
20
  # if the provided values is a symbol, then convert it to an array
16
21
  if values.is_a? Symbol
17
22
  values = [values]
@@ -27,7 +32,7 @@ module DSLCompose
27
32
  raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol or an Array of Symbols"
28
33
  end
29
34
 
30
- @values = values
35
+ @values += values
31
36
  end
32
37
 
33
38
  def validate! value
@@ -112,7 +112,7 @@ module DSLCompose
112
112
  # `description` must be a string with a length greater than 0.
113
113
  # The `description` can only be set once per Argument
114
114
  def set_description description
115
- unless description.is_a?(String) && description.length > 0
115
+ unless description.is_a?(String) && description.strip.length > 0
116
116
  raise InvalidDescriptionError, "The option description `#{description}` is invalid, it must be of type string and have length greater than 0."
117
117
  end
118
118
 
@@ -120,7 +120,7 @@ module DSLCompose
120
120
  raise DescriptionAlreadyExistsError, "The description has already been set"
121
121
  end
122
122
 
123
- @description = FixHeredocIndentation.fix_heredoc_indentation description
123
+ @description = description.strip
124
124
  end
125
125
 
126
126
  # Returns `true` if this DSL has a description, else false.
@@ -230,10 +230,6 @@ module DSLCompose
230
230
  end
231
231
 
232
232
  def validate_in values
233
- if @in_validation
234
- raise ValidationAlreadyExistsError, "The validation `in` has already been applied to this method option."
235
- end
236
-
237
233
  unless values.is_a? Array
238
234
  raise ValidationInvalidArgumentError, values
239
235
  end
@@ -242,14 +238,15 @@ module DSLCompose
242
238
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
243
239
  end
244
240
 
245
- @in_validation = InValidation.new values
241
+ # if this validation has already been applied, then add the values to the existing validation
242
+ if @in_validation
243
+ @in_validation.add_values values
244
+ else
245
+ @in_validation = InValidation.new values
246
+ end
246
247
  end
247
248
 
248
249
  def validate_not_in values
249
- if @not_in_validation
250
- raise ValidationAlreadyExistsError, "The validation `not_in` has already been applied to this method option."
251
- end
252
-
253
250
  unless values.is_a? Array
254
251
  raise ValidationInvalidArgumentError, values
255
252
  end
@@ -258,14 +255,15 @@ module DSLCompose
258
255
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
259
256
  end
260
257
 
261
- @not_in_validation = NotInValidation.new values
258
+ # if this validation has already been applied, then add the values to the existing validation
259
+ if @not_in_validation
260
+ @not_in_validation.add_values values
261
+ else
262
+ @not_in_validation = NotInValidation.new values
263
+ end
262
264
  end
263
265
 
264
266
  def validate_end_with value
265
- if @end_with_validation
266
- raise ValidationAlreadyExistsError, "The validation `end_with` has already been applied to this method option."
267
- end
268
-
269
267
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
270
268
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
271
269
  end
@@ -274,14 +272,15 @@ module DSLCompose
274
272
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
275
273
  end
276
274
 
277
- @end_with_validation = EndWithValidation.new value
275
+ # if this validation has already been applied, then add the values to the existing validation
276
+ if @end_with_validation
277
+ @end_with_validation.add_values value
278
+ else
279
+ @end_with_validation = EndWithValidation.new value
280
+ end
278
281
  end
279
282
 
280
283
  def validate_not_end_with value
281
- if @not_end_with_validation
282
- raise ValidationAlreadyExistsError, "The validation `not_end_with` has already been applied to this method option."
283
- end
284
-
285
284
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
286
285
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
287
286
  end
@@ -290,14 +289,15 @@ module DSLCompose
290
289
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
291
290
  end
292
291
 
293
- @not_end_with_validation = NotEndWithValidation.new value
292
+ # if this validation has already been applied, then add the values to the existing validation
293
+ if @not_end_with_validation
294
+ @not_end_with_validation.add_values value
295
+ else
296
+ @not_end_with_validation = NotEndWithValidation.new value
297
+ end
294
298
  end
295
299
 
296
300
  def validate_start_with value
297
- if @start_with_validation
298
- raise ValidationAlreadyExistsError, "The validation `start_with` has already been applied to this method option."
299
- end
300
-
301
301
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
302
302
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
303
303
  end
@@ -306,14 +306,15 @@ module DSLCompose
306
306
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
307
307
  end
308
308
 
309
- @start_with_validation = StartWithValidation.new value
309
+ # if this validation has already been applied, then add the values to the existing validation
310
+ if @start_with_validation
311
+ @start_with_validation.add_values value
312
+ else
313
+ @start_with_validation = StartWithValidation.new value
314
+ end
310
315
  end
311
316
 
312
317
  def validate_not_start_with value
313
- if @not_start_with_validation
314
- raise ValidationAlreadyExistsError, "The validation `not_start_with` has already been applied to this method option."
315
- end
316
-
317
318
  unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
318
319
  raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
319
320
  end
@@ -322,7 +323,12 @@ module DSLCompose
322
323
  raise ValidationIncompatibleError, "The validation type #{@type} is not compatible with this argument type"
323
324
  end
324
325
 
325
- @not_start_with_validation = NotStartWithValidation.new value
326
+ # if this validation has already been applied, then add the values to the existing validation
327
+ if @not_start_with_validation
328
+ @not_start_with_validation.add_values value
329
+ else
330
+ @not_start_with_validation = NotStartWithValidation.new value
331
+ end
326
332
  end
327
333
 
328
334
  def validate_length maximum: nil, minimum: nil, is: nil
@@ -68,7 +68,7 @@ module DSLCompose
68
68
  # `description` must be a string with a length greater than 0.
69
69
  # The `description` can only be set once per DSLMethod
70
70
  def set_description description
71
- unless description.is_a?(String) && description.length > 0
71
+ unless description.is_a?(String) && description.strip.length > 0
72
72
  raise InvalidDescriptionError, "The DSL method description `#{description}` is invalid, it must be of type string and have length greater than 0"
73
73
  end
74
74
 
@@ -76,7 +76,7 @@ module DSLCompose
76
76
  raise DescriptionAlreadyExistsError, "The description has already been set"
77
77
  end
78
78
 
79
- @description = FixHeredocIndentation.fix_heredoc_indentation description
79
+ @description = description.strip
80
80
  end
81
81
 
82
82
  # Returns `true` if this DSL has a description, else false.
@@ -74,7 +74,7 @@ module DSLCompose
74
74
  # `description` must be a string with a length greater than 0.
75
75
  # The `description` can only be set once per DSL
76
76
  def set_description description
77
- unless description.is_a?(String) && description.length > 0
77
+ unless description.is_a?(String) && description.strip.length > 0
78
78
  raise InvalidDescriptionError, "The DSL description `#{description}` is invalid, it must be of type string and have length greater than 0"
79
79
  end
80
80
 
@@ -82,7 +82,7 @@ module DSLCompose
82
82
  raise DescriptionAlreadyExistsError, "The DSL description has already been set"
83
83
  end
84
84
 
85
- @description = FixHeredocIndentation.fix_heredoc_indentation description
85
+ @description = description.strip
86
86
  end
87
87
 
88
88
  # Returns `true` if this DSL has a description, else false.
@@ -44,10 +44,11 @@ module DSLCompose
44
44
  raise TooManyArgumentsError, "Too many arguments provided"
45
45
  end
46
46
 
47
- # assume all optonal arguments are nil. If actual values were provided, then they will be set below
47
+ # Assume all optonal arguments are nil (except booleans, which default to false).
48
+ # If actual values were provided, then they will be set further below.
48
49
  if arguments.optional_arguments.any?
49
50
  arguments.optional_arguments.each do |optional_argument|
50
- @arguments[optional_argument.name] = nil
51
+ @arguments[optional_argument.name] = (optional_argument.type == :boolean) ? false : nil
51
52
  end
52
53
  end
53
54
 
@@ -5,6 +5,9 @@ module DSLCompose
5
5
  class Execution
6
6
  class MethodCalls
7
7
  class MethodCall
8
+ class InvalidDescriptionError < StandardError
9
+ end
10
+
8
11
  attr_reader :dsl_method
9
12
  attr_reader :arguments
10
13
 
@@ -26,8 +29,12 @@ module DSLCompose
26
29
  # the parser can provide usage notes for how this dsl is being used, these are used to
27
30
  # generate documentation
28
31
  def add_parser_usage_note note
32
+ unless note.is_a?(String) && note.strip.length > 0
33
+ raise InvalidDescriptionError, "The parser usage description `#{note}` is invalid, it must be of type string and have length greater than 0"
34
+ end
35
+
29
36
  @parser_usage_notes ||= []
30
- @parser_usage_notes << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
37
+ @parser_usage_notes << note.strip
31
38
  end
32
39
 
33
40
  # return the list of notes which describe how the parsers are using this DSL
@@ -9,6 +9,9 @@ module DSLCompose
9
9
  class RequiredMethodNotCalledError < StandardError
10
10
  end
11
11
 
12
+ class InvalidDescriptionError < StandardError
13
+ end
14
+
12
15
  attr_reader :dsl
13
16
  attr_reader :klass
14
17
  attr_reader :method_calls
@@ -39,8 +42,12 @@ module DSLCompose
39
42
  # the parser can provide usage notes for how this dsl is being used, these are used to
40
43
  # generate documentation
41
44
  def add_parser_usage_note note
45
+ unless note.is_a?(String) && note.strip.length > 0
46
+ raise InvalidDescriptionError, "The parser usage description `#{note}` is invalid, it must be of type string and have length greater than 0"
47
+ end
48
+
42
49
  @parser_usage_notes ||= []
43
- @parser_usage_notes << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
50
+ @parser_usage_notes << note.strip
44
51
  end
45
52
 
46
53
  # return the list of notes which describe how the parsers are using this DSL
@@ -7,6 +7,9 @@ module DSLCompose
7
7
  class DSLExecutionNotFoundError < StandardError
8
8
  end
9
9
 
10
+ class InvalidDescriptionError < StandardError
11
+ end
12
+
10
13
  # A dynamic DSL can be used multiple times on the same class, each time the DSL is used
11
14
  # a corresponding execution will be created. The execution contains the resulting configuration
12
15
  # from that particular use of the DSL.
@@ -19,9 +22,12 @@ module DSLCompose
19
22
  # the parser can provide usage notes for how this dsl is being used, these are used to
20
23
  # generate documentation
21
24
  def add_parser_usage_note child_class, note
25
+ unless note.is_a?(String) && note.strip.length > 0
26
+ raise InvalidDescriptionError, "The parser usage description `#{note}` is invalid, it must be of type string and have length greater than 0"
27
+ end
22
28
  @parser_usage_notes ||= {}
23
29
  @parser_usage_notes[child_class] ||= []
24
- @parser_usage_notes[child_class] << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
30
+ @parser_usage_notes[child_class] << note.strip
25
31
  end
26
32
 
27
33
  # return the list of notes which describe how the parsers are using this DSL
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.4.0"
4
+ VERSION = "2.5.1"
5
5
  end
data/lib/dsl_compose.rb CHANGED
@@ -51,8 +51,6 @@ require "dsl_compose/composer"
51
51
 
52
52
  require "dsl_compose/class_coerce"
53
53
 
54
- require "dsl_compose/fix_heredoc_indentation"
55
-
56
54
  require "dsl_compose/shared_configuration"
57
55
 
58
56
  require "dsl_compose/dsls"
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.4.0
4
+ version: 2.5.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-07-31 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper
@@ -62,7 +62,6 @@ files:
62
62
  - lib/dsl_compose/dsl/dsl_method/interpreter.rb
63
63
  - lib/dsl_compose/dsl/interpreter.rb
64
64
  - lib/dsl_compose/dsls.rb
65
- - lib/dsl_compose/fix_heredoc_indentation.rb
66
65
  - lib/dsl_compose/interpreter.rb
67
66
  - lib/dsl_compose/interpreter/execution.rb
68
67
  - lib/dsl_compose/interpreter/execution/arguments.rb
@@ -1,21 +0,0 @@
1
- module DSLCompose
2
- # A small helper to fix indentation and clean up whitespace in
3
- # strings which were created with rubys heredoc syntax.
4
- module FixHeredocIndentation
5
- # This method is used to trim empty lines from the start and end of
6
- # a block of markdown, it will also fix the indentation of heredoc
7
- # strings by removing the leading whitespace from the first line, and
8
- # that same amount of white space from every other line
9
- def self.fix_heredoc_indentation string
10
- # replace all tabs with spaces
11
- string = string.gsub(/\t/, " ")
12
- # remove empty lines from the start of the string
13
- string = string.gsub(/\A( *\n)+/, "")
14
- # remove empty lines from the end of the string
15
- string = string.gsub(/( *\n)+\Z/, "")
16
- # removes the number of leading spaces on the first line, from
17
- # all the other lines
18
- string.gsub(/^#{string[/\A */]}/, "")
19
- end
20
- end
21
- end