dsl_compose 1.4.0 → 1.5.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 +23 -23
- data/lib/dsl_compose/parser.rb +19 -1
- data/lib/dsl_compose/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f215d3a5226d56e6f0f5e62b340e0212607a52c3097228f7fc24ef1f5028a20
|
4
|
+
data.tar.gz: afcf1aa8a22966ca83475f7e0d41780c5e0d44e50b13dc91b33a71011b6d1fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff6880b4032551cabd769fa1c2c6eda13179f4b1e50cb652bdef9a6ecd0055e45994235d0ebb78ee06445086368c304279fa04feddcde41b78e046677aea86c
|
7
|
+
data.tar.gz: 409bae7843d156e2c1e6854ebd87381c2eafcccc8adaf3cd2adfbcc076282efde0d0d12c69fb661f95ac0404c7bfd1b28328bdc6e54f211790fb62571b1dd7a0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.5.0](https://github.com/craigulliott/dsl_compose/compare/v1.4.0...v1.5.0) (2023-07-07)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* adding a parser method to rerun the parser, this is most useful from within a test suite when you are testing the parser itself ([#15](https://github.com/craigulliott/dsl_compose/issues/15)) ([fe4de0e](https://github.com/craigulliott/dsl_compose/commit/fe4de0e53f78aff34de4ba1c432b10022d2b6ab4))
|
9
|
+
|
3
10
|
## [1.4.0](https://github.com/craigulliott/dsl_compose/compare/v1.3.0...v1.4.0) (2023-06-26)
|
4
11
|
|
5
12
|
|
data/README.md
CHANGED
@@ -11,9 +11,9 @@ Ruby gem to add dynamic DSLs to classes
|
|
11
11
|
|
12
12
|
* Contains a simple internal DSL which is used to declare dynamic DSLs on your classes
|
13
13
|
* Takes special care not to pollute the namespace of classes where it is used
|
14
|
-
* Use of your declared DSLs is validated at run time
|
15
|
-
* Automatically generate documentation
|
16
|
-
*
|
14
|
+
* Use of your declared DSLs is strictly validated at run time
|
15
|
+
* Automatically generate documentation for your DSLs
|
16
|
+
* Extensive test coverage
|
17
17
|
* Very lightweight and no external dependencies
|
18
18
|
|
19
19
|
## Installation
|
@@ -28,7 +28,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
DSLs are added to classes by including the DSLCompose::Composer module, and then calling the define_dsl singleton method
|
31
|
+
DSLs are defined and added to classes by including the `DSLCompose::Composer` module, and then calling the `define_dsl` singleton method on that class. Those DSLs can then be used on child classes (classes which extend the original class).
|
32
32
|
|
33
33
|
### Defining your DSL
|
34
34
|
|
@@ -36,11 +36,11 @@ DSLs are added to classes by including the DSLCompose::Composer module, and then
|
|
36
36
|
class Foo
|
37
37
|
include DSLCompose::Composer
|
38
38
|
|
39
|
-
# Define and name
|
39
|
+
# Define and name your DSL. Your DSL will be available on this
|
40
40
|
# class and any children of this class.
|
41
|
-
define_dsl :
|
41
|
+
define_dsl :your_dsl do
|
42
42
|
|
43
|
-
# A description of your DSL
|
43
|
+
# A description of your DSL
|
44
44
|
description <<-DESCRIPTION
|
45
45
|
Add a description of your DSL here, this description will be
|
46
46
|
used when generating the documentation for your DSL.
|
@@ -49,8 +49,8 @@ class Foo
|
|
49
49
|
DESCRIPTION
|
50
50
|
|
51
51
|
# You can add required or optional arguments to the initial method which is used
|
52
|
-
# to
|
53
|
-
# `required`)
|
52
|
+
# to call your dynamic DSL (for optional arguments, use `optional` instead of
|
53
|
+
# `required`)
|
54
54
|
#
|
55
55
|
# Arguments are validated, and their expected type must be defined. Supported
|
56
56
|
# argument types are :integer, :boolean, :float, :string or :symbol
|
@@ -66,29 +66,29 @@ class Foo
|
|
66
66
|
# You should provide descriptions for your methods. These descriptions will
|
67
67
|
# be used when generating your documentation. Both of these descriptions
|
68
68
|
# accept markdown
|
69
|
-
description "A description of
|
69
|
+
description "A description of your method"
|
70
70
|
|
71
|
-
#
|
71
|
+
# Add your method argument definition here
|
72
72
|
end
|
73
73
|
|
74
|
-
# Define a required within your DSL.
|
75
|
-
# does not execute this method
|
74
|
+
# Define a required method within your DSL. An error will be raised if a class
|
75
|
+
# uses your DSL but does not execute this method
|
76
76
|
add_method :a_required_method, required: true do
|
77
|
-
#
|
77
|
+
# Add your description here
|
78
|
+
# Add any method arguments here (more info below about method arguments)
|
78
79
|
end
|
79
80
|
|
80
81
|
# Define a method which can only be called once within your DSL. These
|
81
|
-
# methods will raise an error of they are called multiple times.
|
82
|
+
# "unique" methods will raise an error of they are called multiple times.
|
82
83
|
#
|
83
|
-
#
|
84
|
+
# unique methods can be optionally marked as required.
|
84
85
|
add_unique_method :an_optional_method do
|
85
|
-
#
|
86
|
+
# Add your description and any method arguments here (more info below about method arguments)
|
86
87
|
end
|
87
88
|
|
88
89
|
# Define a method in your DSL which takes arguments
|
89
|
-
add_method :
|
90
|
-
|
91
|
-
description "A description of my DSL method"
|
90
|
+
add_method :your_method do
|
91
|
+
description "A description of your DSL method"
|
92
92
|
|
93
93
|
# You can add required arguments to your methods. The order in which you
|
94
94
|
# define these arguments determines the order of the arguments in your final DSL.
|
@@ -96,7 +96,7 @@ class Foo
|
|
96
96
|
# Arguments are validated, and their expected type must be defined. Supported
|
97
97
|
# argument types are :integer, :boolean, :float, :string or :symbol
|
98
98
|
requires :first_method_argument, :string do
|
99
|
-
# You should provide descriptions for your arguments. These descriptions will
|
99
|
+
# You should provide descriptions for your arguments too. These descriptions will
|
100
100
|
# be used when generating your documentation. This description supports markdown
|
101
101
|
description "A description of the first argument for this method"
|
102
102
|
end
|
@@ -124,8 +124,8 @@ Child classes can then use your new DSL
|
|
124
124
|
```ruby
|
125
125
|
class Bar << Foo
|
126
126
|
|
127
|
-
|
128
|
-
|
127
|
+
your_dsl :first_dsl_argument, do
|
128
|
+
your_method "first_method_argument", optional_argument: 123
|
129
129
|
end
|
130
130
|
|
131
131
|
end
|
data/lib/dsl_compose/parser.rb
CHANGED
@@ -27,10 +27,28 @@ module DSLCompose
|
|
27
27
|
# the first step in defining a parser is to set the base_class, this method
|
28
28
|
# will yield to the provided block for each child class of the provided base_class
|
29
29
|
# provided that the child_class uses at least one of the base_classes defined DSLs
|
30
|
-
def self.for_children_of base_class, &block
|
30
|
+
def self.for_children_of base_class, rerun = false, &block
|
31
|
+
unless rerun
|
32
|
+
@runs ||= []
|
33
|
+
@runs << {
|
34
|
+
base_class: base_class,
|
35
|
+
block: block
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
31
39
|
# we parse the provided block in the context of the ForChildrenOfParser class
|
32
40
|
# to help make this code more readable, and to limit polluting the current namespace
|
33
41
|
ForChildrenOfParser.new(base_class, &block)
|
34
42
|
end
|
43
|
+
|
44
|
+
# this method is used to rerun the parser, this is most useful from within a test suite
|
45
|
+
# when you are testing the parser itself
|
46
|
+
def self.rerun
|
47
|
+
@runs&.each do |run|
|
48
|
+
base_class = run[:base_class]
|
49
|
+
block = run[:block]
|
50
|
+
for_children_of base_class, true, &block
|
51
|
+
end
|
52
|
+
end
|
35
53
|
end
|
36
54
|
end
|
data/lib/dsl_compose/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.5.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-
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem to add dynamic DSLs to classes. DSLs are added to classes by
|
14
14
|
including the DSLCompose module, and then calling the add_dsl singleton method within
|