dsl_compose 1.4.0 → 1.6.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: c1a173b5c152d3e0e4ac3867b9f55989593a82f724ad27c26aa0445500c81295
4
- data.tar.gz: 391d451dcef58cf46915b0b54249b527097210d916aa041e1d49de4c576845d8
3
+ metadata.gz: 51a691703918ebafb30bb7c158e627e6a02597e9171e38d1b87cd4cd066d825d
4
+ data.tar.gz: 4e750c6839f7946299f13e81b8af0a7ca94e8d852d7a418f8be97658a0ba67a8
5
5
  SHA512:
6
- metadata.gz: 9d049bc5ed8c830468376cefcb198fc2671c7eff26b9a0a3fff33377d0ac2c27c03f2b2c2fa1527ef648a847667d5fe58b814c355f058e5cb3bceb80439e0ac7
7
- data.tar.gz: 7af648a16098f0ce9b6a0c20936b0b87195cf0e2c8e7869769b5ff293d059b6ca39a0da30b15fb1605d558faeaf5965e616c3cb253bc34daec6e683879ee4da9
6
+ metadata.gz: aa82b56b1c7b6cfcbf4b0116c34b4084f5873cd5d957ceb615b16ab4b36f44a6d3da1ffea8a8ef779b837322d0622254e8688fa4fecffdcb6a011a531aa31106
7
+ data.tar.gz: b1d02bc6e922d35aeee52095bfd3847d5ae347ef56e6278a4f90bb4c76666e0829dad6638956f96a555400a129160f5431d197b264dc1103532c2a1b6df14de2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.0](https://github.com/craigulliott/dsl_compose/compare/v1.5.0...v1.6.0) (2023-07-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * added an interpreter clear method to erase state between tests ([#17](https://github.com/craigulliott/dsl_compose/issues/17)) ([9d0a0c9](https://github.com/craigulliott/dsl_compose/commit/9d0a0c9c521bed61f08fecaa388d1410f513498b))
9
+
10
+ ## [1.5.0](https://github.com/craigulliott/dsl_compose/compare/v1.4.0...v1.5.0) (2023-07-07)
11
+
12
+
13
+ ### Features
14
+
15
+ * 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))
16
+
3
17
  ## [1.4.0](https://github.com/craigulliott/dsl_compose/compare/v1.3.0...v1.4.0) (2023-06-26)
4
18
 
5
19
 
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 and instructions for your DSLs
16
- * Complete test coverage
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 within the class or a child class.
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 the DSL. Your DSL will available on this
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 :my_dsl do
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 enter your dynamic DSL (for optional arguments, use `optional` instead of
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 my awesome method"
69
+ description "A description of your method"
70
70
 
71
- # add your method argument definition here
71
+ # Add your method argument definition here
72
72
  end
73
73
 
74
- # Define a required within your DSL. If a class uses your DSL but
75
- # does not execute this method then an error will be raised.
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
- # add your description and method argument definition here (see below)
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
- # There "unique" methods can be optionally marked as required.
84
+ # unique methods can be optionally marked as required.
84
85
  add_unique_method :an_optional_method do
85
- # add your description and method argument definition here (see below)
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 :my_method do
90
- # A description of my DSL method
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
- my_dsl :first_dsl_argument, do
128
- my_method "first_method_argument", optional_argument: 123
127
+ your_dsl :first_dsl_argument, do
128
+ your_method "first_method_argument", optional_argument: 123
129
129
  end
130
130
 
131
131
  end
@@ -37,6 +37,13 @@ module DSLCompose
37
37
  @executions.filter { |e| e.klass == klass && e.dsl.name == dsl_name }
38
38
  end
39
39
 
40
+ # removes all executions from the interpreter, this is primarily used from
41
+ # within a test suite when dynamically creating classes for tests and then
42
+ # wanting to clear the interpreter before the next test.
43
+ def clear
44
+ @executions = []
45
+ end
46
+
40
47
  def to_h dsl_name
41
48
  h = {}
42
49
  dsl_executions(dsl_name).each do |execution|
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "1.4.0"
4
+ VERSION = "1.6.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: 1.4.0
4
+ version: 1.6.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-06-26 00:00:00.000000000 Z
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