dsl_compose 1.9.1 → 1.10.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: 7fc1bd78d6f3926b9ee718a6e2191cefd5aecd40fcfbb5de9a8cfbd8c602e65c
4
- data.tar.gz: 7b9fd87ecf61b71831f56ab9120562cb3fbb3d49424dc7862c31014e6dc96d45
3
+ metadata.gz: d4269fe819882b592d12b6cce51673a6ef4d87116521ff267c76a7a23aab0382
4
+ data.tar.gz: 9f13611b9417a7e34f0f81d4ccfda152eb5593168a483a011ccf2949a5624937
5
5
  SHA512:
6
- metadata.gz: d3f750f7d8d5d1d7b2014cd84ad10d656d005e2738b18c8ed89f108656b5f9037a428f6ec1094af5382d9788985f3c205c68f06198c8a18e2dfc01f518203cb6
7
- data.tar.gz: 12a823a699962ee5426a53ab66517f5acb23bd1fbc6834b219d6209d09ba78a9a9b249a1169497a0a2773287f24abf2d7c065c3f126f702bf4927c13180a15aa
6
+ metadata.gz: 8923178c3d5ce6ab78229eb22a86412f2b4e7c9da41528b0b752965438dde12c6e8bfb1930880433ab4db2490efd36e15243e907f402544e4c2281a0b81f42e4
7
+ data.tar.gz: e5a0d13825e052290e865365a933b36f6dedcc668f5642283e7f6cbe227617697e83898dec9224179f9f569aa7727a1a6b796201441377431d19ba2235d69fd3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.10.0](https://github.com/craigulliott/dsl_compose/compare/v1.9.1...v1.10.0) (2023-07-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * ability to easily share configuration between multiple DSLs ([#27](https://github.com/craigulliott/dsl_compose/issues/27)) ([38ff61b](https://github.com/craigulliott/dsl_compose/commit/38ff61bed7c9d4357a0019c40fc20bc54d62bebb))
9
+
3
10
  ## [1.9.1](https://github.com/craigulliott/dsl_compose/compare/v1.9.0...v1.9.1) (2023-07-11)
4
11
 
5
12
 
data/README.md CHANGED
@@ -15,6 +15,7 @@ Ruby gem to add dynamic DSLs to classes
15
15
  * Automatically generate documentation for your DSLs
16
16
  * Extensive test coverage
17
17
  * Very lightweight and no external dependencies
18
+ * Share common DSL configuration between DSLs
18
19
 
19
20
  ## Installation
20
21
 
@@ -117,6 +118,39 @@ end
117
118
 
118
119
  ```
119
120
 
121
+ ### Shared Configuration
122
+
123
+ If you are composing many DSLs across one or many classes and these DSLs share common configuration, then you can share configuration between them.
124
+
125
+ Define your shared configuration
126
+
127
+ ```ruby
128
+ DSLCompose::SharedConfiguration.add :my_common_validators do
129
+ validate_not_end_with [:_id, :_at, :_count, :_type]
130
+ validate_not_in [:type, :stage]
131
+ validate_length minimum: 0, maximum: 10
132
+ validate_format /\A[a-z]+(_[a-z]+)*\Z/
133
+ end
134
+ ```
135
+
136
+ Use your shared DSL from within any of your DSL compositions
137
+
138
+ ```ruby
139
+ class Foo
140
+ include DSLCompose::Composer
141
+
142
+ define_dsl :your_dsl do
143
+ optional :optional_argument, :integer do
144
+ # this will import and apply your shared configuration
145
+ import_shared :my_common_validators
146
+ end
147
+
148
+ end
149
+ end
150
+ ```
151
+
152
+ You can use `import_shared` anywhere within your DSL definition, you can even use `import_shared` within other shared configuration
153
+
120
154
  ### Using your DSL
121
155
 
122
156
  Child classes can then use your new DSL
@@ -99,6 +99,14 @@ module DSLCompose
99
99
  def validate_format regexp
100
100
  @argument.validate_format regexp
101
101
  end
102
+
103
+ # executes the shared configuration block with the given name within the
104
+ # context of this part of the DSL, this is a mechanism to share configuration
105
+ # between DSLs
106
+ def import_shared shared_configuration_name
107
+ block = SharedConfiguration.get shared_configuration_name
108
+ instance_eval(&block)
109
+ end
102
110
  end
103
111
  end
104
112
  end
@@ -51,6 +51,14 @@ module DSLCompose
51
51
  def requires name, type, &block
52
52
  @dsl_method.arguments.add_argument name, true, type, &block
53
53
  end
54
+
55
+ # executes the shared configuration block with the given name within the
56
+ # context of this part of the DSL, this is a mechanism to share configuration
57
+ # between DSLs
58
+ def import_shared shared_configuration_name
59
+ block = SharedConfiguration.get shared_configuration_name
60
+ instance_eval(&block)
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -67,6 +67,14 @@ module DSLCompose
67
67
  def requires name, type, &block
68
68
  @dsl.arguments.add_argument name, true, type, &block
69
69
  end
70
+
71
+ # executes the shared configuration block with the given name within the
72
+ # context of this part of the DSL, this is a mechanism to share configuration
73
+ # between DSLs
74
+ def import_shared shared_configuration_name
75
+ block = SharedConfiguration.get shared_configuration_name
76
+ instance_eval(&block)
77
+ end
70
78
  end
71
79
  end
72
80
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSLCompose
4
+ # This module is used to store shared configuration blocks which can be imported and
5
+ # used within your base or method dsl configuration blocks.
6
+ module SharedConfiguration
7
+ class SharedConfigurationAlreadyExistsError < StandardError
8
+ end
9
+
10
+ class SharedConfigurationDoesNotExistError < StandardError
11
+ end
12
+
13
+ class InvalidSharedConfigurationNameError < StandardError
14
+ end
15
+
16
+ class NoBlockProvidedError < StandardError
17
+ end
18
+
19
+ # takes a name and a block and stores it in the shared_configuration hash
20
+ # if a block with this name already exists, it raises an error
21
+ def self.add name, &block
22
+ raise InvalidSharedConfigurationNameError unless name.is_a?(Symbol)
23
+ raise SharedConfigurationAlreadyExistsError if @shared_configuration&.key?(name)
24
+ raise NoBlockProvidedError if block.nil?
25
+
26
+ @shared_configuration ||= {}
27
+ @shared_configuration[name] = block
28
+ end
29
+
30
+ # takes a name and returns the block stored in the shared_configuration hash
31
+ # if a block with this name does not exist, it raises an error
32
+ def self.get name
33
+ raise InvalidSharedConfigurationNameError unless name.is_a?(Symbol)
34
+ raise SharedConfigurationDoesNotExistError unless @shared_configuration&.key?(name)
35
+
36
+ @shared_configuration[name]
37
+ end
38
+
39
+ # clears the shared_configuration hash, this is typically used from the test suite
40
+ def self.clear
41
+ @shared_configuration = {}
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSLCompose
4
- VERSION = "1.9.1"
4
+ VERSION = "1.10.0"
5
5
  end
data/lib/dsl_compose.rb CHANGED
@@ -41,6 +41,8 @@ require "dsl_compose/parser"
41
41
 
42
42
  require "dsl_compose/composer"
43
43
 
44
+ require "dsl_compose/shared_configuration"
45
+
44
46
  require "dsl_compose/dsls"
45
47
 
46
48
  module DSLCompose
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.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ulliott
@@ -56,6 +56,7 @@ files:
56
56
  - lib/dsl_compose/parser/for_children_of_parser.rb
57
57
  - lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser.rb
58
58
  - lib/dsl_compose/parser/for_children_of_parser/for_dsl_parser/for_method_parser.rb
59
+ - lib/dsl_compose/shared_configuration.rb
59
60
  - lib/dsl_compose/version.rb
60
61
  homepage:
61
62
  licenses: