dsl_compose 2.6.1 → 2.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: 5ab97e49cd1581273bc3555e75d7610cab0764024f5c87445cf7da2f48af97d4
4
- data.tar.gz: bc8e659445fad939868276749ae23c8e5cd3a44d7afb45989d4cd5dac4b487a2
3
+ metadata.gz: c6fea0a926ea88fad5e75633a95629a75105580958b512baae3362c47aa2384c
4
+ data.tar.gz: '03486a86365c848b0815d768eb7de00478bebeb8b87d9412a4b06db67857ebcd'
5
5
  SHA512:
6
- metadata.gz: 3e7e18eec99d3b458d1a03e5a9feff3aad70696318d706bf17064646ceeb152d45f4b0b954aef83cb5edcf501502d76821a44c2da58f88d60a91cba31ae18c70
7
- data.tar.gz: 8412d42847af88966b8e523ccda0c37f2724d71c319b244cb1a1f206694899b0cad65e5aaf48d9252e597dd9c1afc8ae50f3bc13e6d4b0459669340f7d242dbb
6
+ metadata.gz: 550d159aca95511d2409fb085ba865f9230ac67fb29ddece4e2f7bbfcf054033e8ce598d6f2ff00d088c27a266c14fdaf1f4405808a6a99fe7ed6888bfeef6a8
7
+ data.tar.gz: 69c5444f0064dbe31a3da9be2a0712fc419758d3ca661ecf70a22429e80d4581e451a1840a28a7fc2d44902b183d20dc9069036d0f062ad78465de6c58a86a4c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.8.0](https://github.com/craigulliott/dsl_compose/compare/v2.7.0...v2.8.0) (2023-08-31)
4
+
5
+
6
+ ### Features
7
+
8
+ * adding a rerun_all singleton method to re-execute all parsers in the system (useful from within specs) ([d0c4ee3](https://github.com/craigulliott/dsl_compose/commit/d0c4ee3cc41da45e774a17ab9d57990dbbf59603))
9
+
10
+ ## [2.7.0](https://github.com/craigulliott/dsl_compose/compare/v2.6.1...v2.7.0) (2023-08-29)
11
+
12
+
13
+ ### Features
14
+
15
+ * adding `namespace` and `title` methods to DSL generation. These help with documentation generation ([1bdf16d](https://github.com/craigulliott/dsl_compose/commit/1bdf16de6c1dc872809cc66d6599c36b3a1f1e99))
16
+
3
17
  ## [2.6.1](https://github.com/craigulliott/dsl_compose/compare/v2.6.0...v2.6.1) (2023-08-29)
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
  #
@@ -32,12 +32,17 @@ module DSLCompose
32
32
  # children of their own)
33
33
  def self.for_children_of base_class, final_children_only: false, rerun: false, &block
34
34
  unless rerun
35
- @runs ||= []
36
- @runs << {
35
+ run = {
37
36
  base_class: base_class,
38
37
  final_children_only: final_children_only,
39
38
  block: block
40
39
  }
40
+
41
+ @@all_runs ||= []
42
+ @@all_runs << run
43
+
44
+ @runs ||= []
45
+ @runs << run
41
46
  end
42
47
 
43
48
  # we parse the provided block in the context of the ForChildrenOfParser class
@@ -56,7 +61,7 @@ module DSLCompose
56
61
  # this method is used to rerun the parser, this is most useful from within a test suite
57
62
  # when you are testing the parser itself
58
63
  def self.rerun
59
- # rerun each parset tests
64
+ # rerun each parser for this specific class
60
65
  @runs&.each do |run|
61
66
  base_class = run[:base_class]
62
67
  block = run[:block]
@@ -64,5 +69,17 @@ module DSLCompose
64
69
  for_children_of base_class, rerun: true, final_children_only: final_children_only, &block
65
70
  end
66
71
  end
72
+
73
+ # this method is used to rerun all of the parsers, this is most useful from within a test suite
74
+ # when you are testing the parser itself
75
+ def self.rerun_all
76
+ # rerun each parser for all classes (call this method directly on the parser object `DSLCompose::Parser.rerun_all`)
77
+ @all_runs&.each do |run|
78
+ base_class = run[:base_class]
79
+ block = run[:block]
80
+ final_children_only = run[:final_children_only]
81
+ for_children_of base_class, rerun: true, final_children_only: final_children_only, &block
82
+ end
83
+ end
67
84
  end
68
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "2.6.1"
4
+ VERSION = "2.8.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.1
4
+ version: 2.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-08-29 00:00:00.000000000 Z
11
+ date: 2023-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_spec_helper