dsl_compose 2.6.0 → 2.7.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: '048f2e5d2e94df09db474b6134cacb580dde9a88a751e2e0697d72234be0132e'
4
- data.tar.gz: b336eb45f722b2fbafb0f12f43d760ad1de2287eb9beffc27227d020daf5cc43
3
+ metadata.gz: 9eca7fac101d871e9ce111652e859f93eee66b0c8997fd2d2334231f256b6ebd
4
+ data.tar.gz: 3e858226842b60303d39af62eebc95208ac72b4839f816da45e8d678a078cfbc
5
5
  SHA512:
6
- metadata.gz: 412d7f101db06e26ad871a359d7d063a0086b0b2b3e8be2e96cd3b87e69ec1eb7f813c770326779e9b16c166433700b6751ecf9e8b35e568313f8350ed31fd30
7
- data.tar.gz: 551f08b45107d633abbcdc008fd13e971c41c317e17ce07e86f0035b2d1ee1ef9ddb6e23b2c1505239279d7f90c1940f22b1d111542ecc51a253b588bb101823
6
+ metadata.gz: c779883cc3eb12be2dbb13ed79cda45dff848501be4d23b283dfd1d4de6a59f3ab5301def52b7947e1d03f22671080bae84e290cf05ff7d92432892d97917365
7
+ data.tar.gz: 9e14efabd12ee806787bceffa742007ae6f8d631e87f02856357418458c4d707e8702ca2eabbb8a332f1a60aadcfe73cf641fd5eef811c13ad2dfc231e76269f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.7.0](https://github.com/craigulliott/dsl_compose/compare/v2.6.1...v2.7.0) (2023-08-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * adding `namespace` and `title` methods to DSL generation. These help with documentation generation ([1bdf16d](https://github.com/craigulliott/dsl_compose/commit/1bdf16de6c1dc872809cc66d6599c36b3a1f1e99))
9
+
10
+ ## [2.6.1](https://github.com/craigulliott/dsl_compose/compare/v2.6.0...v2.6.1) (2023-08-29)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * renaming `description` to `add_documentation` for dynamically creating documentation from within parsers ([3e24194](https://github.com/craigulliott/dsl_compose/commit/3e2419492e61d94ea7d3c1f34ef4990fc0f6682a))
16
+
3
17
  ## [2.6.0](https://github.com/craigulliott/dsl_compose/compare/v2.5.2...v2.6.0) (2023-08-23)
4
18
 
5
19
 
data/README.md CHANGED
@@ -130,6 +130,31 @@ end
130
130
 
131
131
  ```
132
132
 
133
+ The methods `title` and `namespace` are also available at the top level of your DSL definition. These methods can provide useful metadata when generating documentation, but are typically only useful in much larger systems involving many different DSLs.
134
+
135
+ ```ruby
136
+ class Foo
137
+ include DSLCompose::Composer
138
+
139
+ # DSLs have some top level methods which allow you to set some useful
140
+ # metadata for use when generating documentation.
141
+ define_dsl :your_dsl do
142
+ # You can give your DSLs a friendly title.
143
+ title "My Friendly DSL Title"
144
+
145
+ # You can also logically group a set of DSLs together by setting the same
146
+ # namespace on each of them.
147
+ namespace :my_namespace
148
+
149
+ # You can also describe this DSL.
150
+ # Unlike `title` and `namespace`, you can set descriptions on all of your
151
+ # DSL methods and arguments too (as seen in the various examples above)
152
+ description "A description of your DSL"
153
+
154
+ end
155
+ end
156
+ ```
157
+
133
158
  ### Shared Configuration
134
159
 
135
160
  If you are composing many DSLs across one or many classes and these DSLs share common configuration, then you can share configuration between them.
@@ -247,7 +272,7 @@ class MyParser < DSLCompose::Parser
247
272
  # which extend the provided base class, but do not have their own children) then
248
273
  # use `for_final_children_of` instead of `for_children_of`
249
274
  for_children_of SomeBaseClass do |child_class:|
250
- description <<~DESCRIPTION
275
+ add_documentation <<~DESCRIPTION
251
276
  You can optionally provide a description of anything specific that your parser
252
277
  does in this block, this description will be used when generating documentation
253
278
 
@@ -281,7 +306,7 @@ class MyParser < DSLCompose::Parser
281
306
  # which were called within this use of your DSL. There is more documentation about
282
307
  # Reader classes below.
283
308
  for_dsl [:dsl1, :dsl2] do |dsl_name:, a_dsl_argument:, reader:|
284
- description <<~DESCRIPTION
309
+ add_documentation <<~DESCRIPTION
285
310
  You can optionally provide a description of anything specific that your parser
286
311
  does in this block, this description will be used when generating documentation.
287
312
 
@@ -308,7 +333,7 @@ class MyParser < DSLCompose::Parser
308
333
  # are provided then the requested dsl argument must be present on all DSLs
309
334
  # otherwise an error will be raised.
310
335
  for_method :some_method_name do |method_name:, a_method_argument:|
311
- description <<~DESCRIPTION
336
+ add_documentation <<~DESCRIPTION
312
337
  You can optionally provide a description of anything specific that your parser
313
338
  does in this block, this description will be used when generating documentation.
314
339
 
@@ -28,6 +28,17 @@ module DSLCompose
28
28
  @dsl.set_description description
29
29
  end
30
30
 
31
+ # sets the namespace of the DSL, this is used
32
+ # to group DSLs together in documentation
33
+ def namespace namespace
34
+ @dsl.set_namespace namespace
35
+ end
36
+
37
+ # sets the title of the DSL
38
+ def title title
39
+ @dsl.set_title title
40
+ end
41
+
31
42
  # adds a new method to the DSL
32
43
  #
33
44
  # methods flagged as `required` will cause your DSLs to raise an error
@@ -21,6 +21,18 @@ module DSLCompose
21
21
  class DescriptionAlreadyExistsError < StandardError
22
22
  end
23
23
 
24
+ class InvalidNamespaceError < StandardError
25
+ end
26
+
27
+ class NamespaceAlreadyExistsError < StandardError
28
+ end
29
+
30
+ class InvalidTitleError < StandardError
31
+ end
32
+
33
+ class TitleAlreadyExistsError < StandardError
34
+ end
35
+
24
36
  class NoBlockProvidedError < StandardError
25
37
  end
26
38
 
@@ -31,6 +43,12 @@ module DSLCompose
31
43
  # An otional description of this DSL, if provided then it must be a string.
32
44
  # The description accepts markdown and is used when generating documentation.
33
45
  attr_reader :description
46
+ # An otional namespace for this DSL, if provided then it must be a Symbol. This
47
+ # is currently used to group DSLs for the sake of documentation.
48
+ attr_reader :namespace
49
+ # An otional namespace for this DSL, if provided then it must be a String. This
50
+ # is currently used when generating documentation.
51
+ attr_reader :title
34
52
  # an object which represents the argument configuration
35
53
  attr_reader :arguments
36
54
 
@@ -85,11 +103,55 @@ module DSLCompose
85
103
  @description = description.strip
86
104
  end
87
105
 
106
+ # Set the namespace for this DSL to the provided value.
107
+ #
108
+ # `namespace` must be a Symbol.
109
+ # The `namespace` can only be set once per DSL
110
+ # this is currently used for grouping together DSLS for the sake of documentation
111
+ def set_namespace namespace
112
+ unless namespace.is_a?(Symbol)
113
+ raise InvalidNamespaceError, "The DSL namespace `#{namespace}` is invalid, it must be of type Symbol"
114
+ end
115
+
116
+ if has_namespace?
117
+ raise NamespaceAlreadyExistsError, "The DSL namespace has already been set"
118
+ end
119
+
120
+ @namespace = namespace
121
+ end
122
+
123
+ # Set the title for this DSL to the provided value.
124
+ #
125
+ # `title` must be a String with a length greater than 0.
126
+ # The `title` can only be set once per DSL
127
+ # this is currently used for documentation
128
+ def set_title title
129
+ unless title.is_a?(String) && title.strip.length > 0
130
+ raise InvalidTitleError, "The DSL title `#{title}` is invalid, it must be of type string and have length greater than 0"
131
+ end
132
+
133
+ if has_title?
134
+ raise TitleAlreadyExistsError, "The DSL title has already been set"
135
+ end
136
+
137
+ @title = title.strip
138
+ end
139
+
88
140
  # Returns `true` if this DSL has a description, else false.
89
141
  def has_description?
90
142
  @description.nil? == false
91
143
  end
92
144
 
145
+ # Returns `true` if this DSL has a namespace, else false.
146
+ def has_namespace?
147
+ @namespace.nil? == false
148
+ end
149
+
150
+ # Returns `true` if this DSL has a title, else false.
151
+ def has_title?
152
+ @title.nil? == false
153
+ end
154
+
93
155
  # Takes a method name, unique flag, required flag, and a block and creates
94
156
  # a new DSLMethod object.
95
157
  #
@@ -148,7 +148,6 @@ module DSLCompose
148
148
  else
149
149
  optional_arg_value
150
150
  end
151
-
152
151
  rescue => e
153
152
  raise e, "Error processing optional argument #{optional_argument_name}: #{e.message}", e.backtrace
154
153
  end
@@ -239,7 +238,6 @@ module DSLCompose
239
238
  else
240
239
  required_arg_value
241
240
  end
242
-
243
241
  rescue => e
244
242
  raise e, "Error processing required argument #{argument_name}: #{e.message}", e.backtrace
245
243
  end
@@ -14,12 +14,12 @@ module DSLCompose
14
14
  @method_calls.filter { |mc| mc.method_name == method_name }.any?
15
15
  end
16
16
 
17
- def add_method_call dsl_method, *args, &block
17
+ def add_method_call(dsl_method, ...)
18
18
  # make sure we always have a variable which can be used in the exception message
19
19
  dsl_method_name = nil
20
20
  dsl_method_name = dsl_method.name
21
21
 
22
- method_call = MethodCall.new(dsl_method, *args, &block)
22
+ method_call = MethodCall.new(dsl_method, ...)
23
23
  @method_calls << method_call
24
24
  method_call
25
25
  rescue => e
@@ -59,7 +59,7 @@ module DSLCompose
59
59
  private
60
60
 
61
61
  # catch and process any method calls within the DSL block
62
- def method_missing method_name, *args, &block
62
+ def method_missing(method_name, ...)
63
63
  # if the method does not exist, then this will raise a MethodDoesNotExistError
64
64
  dsl_method = @dsl.dsl_method method_name
65
65
 
@@ -68,7 +68,7 @@ module DSLCompose
68
68
  raise MethodIsUniqueError, "This method `#{method_name}` is unique and can only be called once within this DSL"
69
69
  end
70
70
 
71
- @method_calls.add_method_call dsl_method, *args, &block
71
+ @method_calls.add_method_call(dsl_method, ...)
72
72
  end
73
73
 
74
74
  def respond_to_missing?(method_name, *args)
@@ -40,14 +40,14 @@ module DSLCompose
40
40
  # Execute/process a dynamically defined DSL on a class.
41
41
  # `klass` is the class in which the DSL is being used, not
42
42
  # the class in which the DSL was defined.
43
- def execute_dsl klass, dsl, *args, &block
43
+ def execute_dsl(klass, dsl, ...)
44
44
  # make sure we have these variables for the exception message below
45
45
  class_name = nil
46
46
  class_name = klass.name
47
47
  dsl_name = nil
48
48
  dsl_name = dsl.name
49
49
 
50
- execution = Execution.new(klass, dsl, *args, &block)
50
+ execution = Execution.new(klass, dsl, ...)
51
51
  @executions << execution
52
52
  execution
53
53
  rescue => e
@@ -107,8 +107,8 @@ module DSLCompose
107
107
  # takes a description of what this parser does and stores it against the DSL definition
108
108
  # of the current @child_class, this is used to generate documentation for what the parser
109
109
  # has done with the DSL
110
- def description description
111
- @method_call.add_parser_usage_note description
110
+ def add_documentation documentation
111
+ @method_call.add_parser_usage_note documentation
112
112
  end
113
113
  end
114
114
  end
@@ -142,8 +142,8 @@ module DSLCompose
142
142
  # takes a description of what this parser does and stores it against the DSL definition
143
143
  # of the current @child_class, this is used to generate documentation for what the parser
144
144
  # has done with the DSL
145
- def description description
146
- @dsl_execution.add_parser_usage_note description
145
+ def add_documentation documentation
146
+ @dsl_execution.add_parser_usage_note documentation
147
147
  end
148
148
  end
149
149
  end
@@ -125,8 +125,8 @@ module DSLCompose
125
125
  # takes a description of what this parser does and stores it against the DSL definition
126
126
  # of the current @child_class, this is used to generate documentation for what the parser
127
127
  # has done with the DSL
128
- def description description
129
- @base_class.dsls.add_parser_usage_note @child_class, description
128
+ def add_documentation documentation
129
+ @base_class.dsls.add_parser_usage_note @child_class, documentation
130
130
  end
131
131
  end
132
132
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.6.0"
4
+ VERSION = "2.7.0"
5
5
  end
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.6.0
4
+ version: 2.7.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-08-23 00:00:00.000000000 Z
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper