dsl_compose 1.13.1 → 1.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +27 -0
- data/lib/dsl_compose/dsl/arguments/argument.rb +1 -1
- data/lib/dsl_compose/dsl/dsl_method.rb +1 -1
- data/lib/dsl_compose/dsl.rb +1 -1
- data/lib/dsl_compose/fix_heredoc_indentation.rb +23 -0
- data/lib/dsl_compose/interpreter/execution/method_calls/method_call.rb +13 -0
- data/lib/dsl_compose/interpreter/execution.rb +13 -0
- data/lib/dsl_compose/interpreter.rb +20 -3
- data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser/for_method_parser.rb +11 -0
- data/lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser.rb +7 -0
- data/lib/dsl_compose/parser/for_children_of_parser.rb +7 -0
- data/lib/dsl_compose/version.rb +1 -1
- data/lib/dsl_compose.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddb7398a7cd392f48c54e7ee60404342857d7d010247926ca006d84ad5caa1ac
|
4
|
+
data.tar.gz: d4515e288a0eea8be71a869434c1f28a20f2cec3943a33c9c6615028b223b970
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8512aec08f472d946b2c9a84b6e824bbc1d46db610f3bb908766e05a324833e3c07feeb05638153633d23bccbe1f0e66e8132721e7056e903beaed1a42ef866c
|
7
|
+
data.tar.gz: a2897b08ed6b226a06c8fbf2e07277b68fc1476b7467db663c06acacaa3a1e92db64b3aaac782fb2ada0657605dfecccb47bce6517339d60a49016a48ccd9726
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.14.1](https://github.com/craigulliott/dsl_compose/compare/v1.14.0...v1.14.1) (2023-07-19)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* Clearing the parser_usage_notes when also clearing the DSLs. ([#41](https://github.com/craigulliott/dsl_compose/issues/41)) ([bbdb445](https://github.com/craigulliott/dsl_compose/commit/bbdb445ed9fa4b495f8aa5bf0b889707680858d0))
|
9
|
+
|
10
|
+
## [1.14.0](https://github.com/craigulliott/dsl_compose/compare/v1.13.1...v1.14.0) (2023-07-19)
|
11
|
+
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* Parsers can push notes back to the DSLs to explain how each DSL is being used. These notes can be used in generated documentation. ([#39](https://github.com/craigulliott/dsl_compose/issues/39)) ([053fa50](https://github.com/craigulliott/dsl_compose/commit/053fa50bcbc2180b2f788b5a3bba11576804f206))
|
16
|
+
|
3
17
|
## [1.13.1](https://github.com/craigulliott/dsl_compose/compare/v1.13.0...v1.13.1) (2023-07-19)
|
4
18
|
|
5
19
|
|
data/README.md
CHANGED
@@ -247,6 +247,16 @@ 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
|
251
|
+
You can optionally provide a description of anything specific that your parser
|
252
|
+
does in this block, this description will be used when generating documentation
|
253
|
+
|
254
|
+
This description accepts markdown.
|
255
|
+
|
256
|
+
Do not add a description here if the parser does not have any business logic here
|
257
|
+
other than making calls to `for_dsl`, `for_dsl_or_inherited_dsl` or `for_inherited_dsl`
|
258
|
+
DESCRIPTION
|
259
|
+
|
250
260
|
# `for_dsl` accepts a DSL name or an array of DSL names and will yield it's
|
251
261
|
# provided block once for each time a DSL of that name has been used
|
252
262
|
# directly on the child_class.
|
@@ -266,6 +276,16 @@ MyParser < DSLCompose::Parser
|
|
266
276
|
# consider a DSL to have been executed on the actual class it was used, and
|
267
277
|
# any classes which are descendants of that class
|
268
278
|
for_dsl [:dsl1, :dsl2] do |dsl_name:, a_dsl_argument:|
|
279
|
+
description <<-DESCRIPTION
|
280
|
+
You can optionally provide a description of anything specific that your parser
|
281
|
+
does in this block, this description will be used when generating documentation.
|
282
|
+
|
283
|
+
This description accepts markdown.
|
284
|
+
|
285
|
+
Do not add a description here if the parser does not have any business logic here
|
286
|
+
other than making calls to `for_method`
|
287
|
+
DESCRIPTION
|
288
|
+
|
269
289
|
# `for_method` accepts a method name or an array of method names and will
|
270
290
|
# yield it's provided block once for each time a method with this name is
|
271
291
|
# executed within the DSL.
|
@@ -277,6 +297,13 @@ MyParser < DSLCompose::Parser
|
|
277
297
|
# are provided then the requested dsl argument must be present on all DSLs
|
278
298
|
# otherwise an error will be raised.
|
279
299
|
for_method :some_method_name do |method_name:, a_method_argument:|
|
300
|
+
description <<-DESCRIPTION
|
301
|
+
You can optionally provide a description of anything specific that your parser
|
302
|
+
does in this block, this description will be used when generating documentation.
|
303
|
+
|
304
|
+
This description accepts markdown.
|
305
|
+
DESCRIPTION
|
306
|
+
|
280
307
|
# your business logic goes here
|
281
308
|
...
|
282
309
|
end
|
@@ -120,7 +120,7 @@ module DSLCompose
|
|
120
120
|
raise DescriptionAlreadyExistsError, "The description has already been set"
|
121
121
|
end
|
122
122
|
|
123
|
-
@description = description
|
123
|
+
@description = FixHeredocIndentation.fix_heredoc_indentation description
|
124
124
|
end
|
125
125
|
|
126
126
|
# Returns `true` if this DSL has a description, else false.
|
@@ -76,7 +76,7 @@ module DSLCompose
|
|
76
76
|
raise DescriptionAlreadyExistsError, "The description has already been set"
|
77
77
|
end
|
78
78
|
|
79
|
-
@description = description
|
79
|
+
@description = FixHeredocIndentation.fix_heredoc_indentation description
|
80
80
|
end
|
81
81
|
|
82
82
|
# Returns `true` if this DSL has a description, else false.
|
data/lib/dsl_compose/dsl.rb
CHANGED
@@ -82,7 +82,7 @@ module DSLCompose
|
|
82
82
|
raise DescriptionAlreadyExistsError, "The DSL description has already been set"
|
83
83
|
end
|
84
84
|
|
85
|
-
@description = description
|
85
|
+
@description = FixHeredocIndentation.fix_heredoc_indentation description
|
86
86
|
end
|
87
87
|
|
88
88
|
# Returns `true` if this DSL has a description, else false.
|
@@ -0,0 +1,23 @@
|
|
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 fix the indentation of heredoc strings.
|
6
|
+
# It will remove the leading whitespace from each line of the string
|
7
|
+
# and remove the leading newline from the string.
|
8
|
+
def self.fix_heredoc_indentation string
|
9
|
+
# replace all tabs with spaces
|
10
|
+
string = string.gsub(/\t/, " ")
|
11
|
+
# remove empty lines from the start of the string
|
12
|
+
string = string.gsub(/\A( *\n)+/, "")
|
13
|
+
# remove empty lines from the end of the string
|
14
|
+
string = string.gsub(/( *\n)+\Z/, "")
|
15
|
+
# removes the number of leading spaces on the first line, from
|
16
|
+
# all the other lines
|
17
|
+
string = string.gsub(/^#{string[/\A */]}/, "")
|
18
|
+
# collapse lines which are next to each other onto the same line
|
19
|
+
# because they are really the same paragraph
|
20
|
+
string.gsub(/([^ \n])\n([^ \n])/, '\1 \2')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -22,6 +22,19 @@ module DSLCompose
|
|
22
22
|
arguments: @arguments.to_h
|
23
23
|
}
|
24
24
|
end
|
25
|
+
|
26
|
+
# the parser can provide usage notes for how this dsl is being used, these are used to
|
27
|
+
# generate documentation
|
28
|
+
def add_parser_usage_note note
|
29
|
+
@parser_usage_notes ||= []
|
30
|
+
@parser_usage_notes << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
|
31
|
+
end
|
32
|
+
|
33
|
+
# return the list of notes which describe how the parsers are using this DSL
|
34
|
+
def parser_usage_notes
|
35
|
+
@parser_usage_notes ||= []
|
36
|
+
@parser_usage_notes
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
@@ -36,6 +36,19 @@ module DSLCompose
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
# the parser can provide usage notes for how this dsl is being used, these are used to
|
40
|
+
# generate documentation
|
41
|
+
def add_parser_usage_note note
|
42
|
+
@parser_usage_notes ||= []
|
43
|
+
@parser_usage_notes << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
|
44
|
+
end
|
45
|
+
|
46
|
+
# return the list of notes which describe how the parsers are using this DSL
|
47
|
+
def parser_usage_notes
|
48
|
+
@parser_usage_notes ||= []
|
49
|
+
@parser_usage_notes
|
50
|
+
end
|
51
|
+
|
39
52
|
private
|
40
53
|
|
41
54
|
# catch and process any method calls within the DSL block
|
@@ -13,6 +13,21 @@ module DSLCompose
|
|
13
13
|
@executions = []
|
14
14
|
end
|
15
15
|
|
16
|
+
# the parser can provide usage notes for how this dsl is being used, these are used to
|
17
|
+
# generate documentation
|
18
|
+
def add_parser_usage_note child_class, note
|
19
|
+
@parser_usage_notes ||= {}
|
20
|
+
@parser_usage_notes[child_class] ||= []
|
21
|
+
@parser_usage_notes[child_class] << DSLCompose::FixHeredocIndentation.fix_heredoc_indentation(note)
|
22
|
+
end
|
23
|
+
|
24
|
+
# return the list of notes which describe how the parsers are using this DSL
|
25
|
+
def parser_usage_notes child_class
|
26
|
+
@parser_usage_notes ||= {}
|
27
|
+
@parser_usage_notes[child_class] ||= []
|
28
|
+
@parser_usage_notes[child_class]
|
29
|
+
end
|
30
|
+
|
16
31
|
# Execute/process a dynamically defined DSL on a class.
|
17
32
|
# `klass` is the class in which the DSL is being used, not
|
18
33
|
# the class in which the DSL was defined.
|
@@ -46,11 +61,13 @@ module DSLCompose
|
|
46
61
|
@executions.filter { |e| e.dsl.name == dsl_name && ((on_current_class && e.klass == klass) || (on_ancestor_class && klass < e.klass)) }
|
47
62
|
end
|
48
63
|
|
49
|
-
# removes all executions from the interpreter,
|
50
|
-
# within a test suite when dynamically creating
|
51
|
-
# wanting to clear the interpreter before the
|
64
|
+
# removes all executions from the interpreter, and any parser_usage_notes
|
65
|
+
# this is primarily used from within a test suite when dynamically creating
|
66
|
+
# classes for tests and then wanting to clear the interpreter before the
|
67
|
+
# next test.
|
52
68
|
def clear
|
53
69
|
@executions = []
|
70
|
+
@parser_usage_notes ||= {}
|
54
71
|
end
|
55
72
|
|
56
73
|
def to_h dsl_name
|
@@ -83,11 +83,22 @@ module DSLCompose
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
# set the method_call in an instance variable so that method calls to `description`
|
87
|
+
# from within the block will have access to it
|
88
|
+
@method_call = method_call
|
89
|
+
|
86
90
|
# yeild the block in the context of this class
|
87
91
|
instance_exec(**args, &block)
|
88
92
|
end
|
89
93
|
end
|
90
94
|
end
|
95
|
+
|
96
|
+
# takes a description of what this parser does and stores it against the DSL definition
|
97
|
+
# of the current @child_class, this is used to generate documentation for what the parser
|
98
|
+
# has done with the DSL
|
99
|
+
def description description
|
100
|
+
@method_call.add_parser_usage_note description
|
101
|
+
end
|
91
102
|
end
|
92
103
|
end
|
93
104
|
end
|
@@ -108,6 +108,13 @@ module DSLCompose
|
|
108
108
|
def for_method method_names, &block
|
109
109
|
ForMethodParser.new(@base_class, @child_class, @dsl_execution, method_names, &block)
|
110
110
|
end
|
111
|
+
|
112
|
+
# takes a description of what this parser does and stores it against the DSL definition
|
113
|
+
# of the current @child_class, this is used to generate documentation for what the parser
|
114
|
+
# has done with the DSL
|
115
|
+
def description description
|
116
|
+
@dsl_execution.add_parser_usage_note description
|
117
|
+
end
|
111
118
|
end
|
112
119
|
end
|
113
120
|
end
|
@@ -121,6 +121,13 @@ module DSLCompose
|
|
121
121
|
def for_dsl_or_inherited_dsl dsl_names, &block
|
122
122
|
for_dsl dsl_names, on_current_class: true, on_ancestor_class: true, &block
|
123
123
|
end
|
124
|
+
|
125
|
+
# takes a description of what this parser does and stores it against the DSL definition
|
126
|
+
# of the current @child_class, this is used to generate documentation for what the parser
|
127
|
+
# has done with the DSL
|
128
|
+
def description description
|
129
|
+
@base_class.dsls.add_parser_usage_note @child_class, description
|
130
|
+
end
|
124
131
|
end
|
125
132
|
end
|
126
133
|
end
|
data/lib/dsl_compose/version.rb
CHANGED
data/lib/dsl_compose.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Ulliott
|
@@ -62,6 +62,7 @@ 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
|
65
66
|
- lib/dsl_compose/interpreter.rb
|
66
67
|
- lib/dsl_compose/interpreter/execution.rb
|
67
68
|
- lib/dsl_compose/interpreter/execution/arguments.rb
|