dsl_compose 2.6.1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +28 -3
- data/lib/dsl_compose/dsl/interpreter.rb +11 -0
- data/lib/dsl_compose/dsl.rb +62 -0
- data/lib/dsl_compose/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eca7fac101d871e9ce111652e859f93eee66b0c8997fd2d2334231f256b6ebd
|
4
|
+
data.tar.gz: 3e858226842b60303d39af62eebc95208ac72b4839f816da45e8d678a078cfbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c779883cc3eb12be2dbb13ed79cda45dff848501be4d23b283dfd1d4de6a59f3ab5301def52b7947e1d03f22671080bae84e290cf05ff7d92432892d97917365
|
7
|
+
data.tar.gz: 9e14efabd12ee806787bceffa742007ae6f8d631e87f02856357418458c4d707e8702ca2eabbb8a332f1a60aadcfe73cf641fd5eef811c13ad2dfc231e76269f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
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
|
+
|
3
10
|
## [2.6.1](https://github.com/craigulliott/dsl_compose/compare/v2.6.0...v2.6.1) (2023-08-29)
|
4
11
|
|
5
12
|
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/dsl_compose/dsl.rb
CHANGED
@@ -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
|
#
|
data/lib/dsl_compose/version.rb
CHANGED