dsl_compose 1.9.0 → 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: 44f916259ac32c44bb38f5c8a423d6e41f9c3b61604715bb1e550b1ab9f5dc64
4
- data.tar.gz: 22a2303459feb386ac8fa0995323fa95001d2312e83d90271d0868f66cf69e82
3
+ metadata.gz: d4269fe819882b592d12b6cce51673a6ef4d87116521ff267c76a7a23aab0382
4
+ data.tar.gz: 9f13611b9417a7e34f0f81d4ccfda152eb5593168a483a011ccf2949a5624937
5
5
  SHA512:
6
- metadata.gz: fcf694293406ec2b317da5a9ea7f9fcfac87efae1ecd8cf481e27325d916b61ffdb23b54909589d01cdbb2e30d1fc612c5f6bd7d6e1618e2db937bf97c43f052
7
- data.tar.gz: a50c27fe9ffab7b47326c1e4826983fe0bcec1428fed0f2d5d7e0b54d928e5c592cba2d8973b88f11e08bcc295f50a6def76058de086d97fd14f98273c656019
6
+ metadata.gz: 8923178c3d5ce6ab78229eb22a86412f2b4e7c9da41528b0b752965438dde12c6e8bfb1930880433ab4db2490efd36e15243e907f402544e4c2281a0b81f42e4
7
+ data.tar.gz: e5a0d13825e052290e865365a933b36f6dedcc668f5642283e7f6cbe227617697e83898dec9224179f9f569aa7727a1a6b796201441377431d19ba2235d69fd3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
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
+
10
+ ## [1.9.1](https://github.com/craigulliott/dsl_compose/compare/v1.9.0...v1.9.1) (2023-07-11)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * bug fix where argument class was using wrong type check for start and end with validators ([#25](https://github.com/craigulliott/dsl_compose/issues/25)) ([d16fd35](https://github.com/craigulliott/dsl_compose/commit/d16fd35d0b574eafe6ad9d68d4e7f5884e89c521))
16
+
3
17
  ## [1.9.0](https://github.com/craigulliott/dsl_compose/compare/v1.8.0...v1.9.0) (2023-07-11)
4
18
 
5
19
 
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
@@ -260,8 +260,8 @@ module DSLCompose
260
260
  raise ValidationAlreadyExistsError, "The validation `end_with` has already been applied to this method option."
261
261
  end
262
262
 
263
- unless value.is_a? Symbol
264
- raise ValidationInvalidArgumentError, value
263
+ unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
264
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
265
265
  end
266
266
 
267
267
  unless @type == :string || @type == :symbol
@@ -276,8 +276,8 @@ module DSLCompose
276
276
  raise ValidationAlreadyExistsError, "The validation `not_end_with` has already been applied to this method option."
277
277
  end
278
278
 
279
- unless value.is_a? Symbol
280
- raise ValidationInvalidArgumentError, value
279
+ unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
280
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
281
281
  end
282
282
 
283
283
  unless @type == :string || @type == :symbol
@@ -292,8 +292,8 @@ module DSLCompose
292
292
  raise ValidationAlreadyExistsError, "The validation `start_with` has already been applied to this method option."
293
293
  end
294
294
 
295
- unless value.is_a? Symbol
296
- raise ValidationInvalidArgumentError, value
295
+ unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
296
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
297
297
  end
298
298
 
299
299
  unless @type == :string || @type == :symbol
@@ -308,8 +308,8 @@ module DSLCompose
308
308
  raise ValidationAlreadyExistsError, "The validation `not_start_with` has already been applied to this method option."
309
309
  end
310
310
 
311
- unless value.is_a? Symbol
312
- raise ValidationInvalidArgumentError, value
311
+ unless value.is_a?(Symbol) || (value.is_a?(Array) && value.all? { |value| value.is_a? Symbol })
312
+ raise ValidationInvalidArgumentError, "The value `#{value}` provided to this validator must be a Symbol or an Array of Symbols"
313
313
  end
314
314
 
315
315
  unless @type == :string || @type == :symbol
@@ -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.0"
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.0
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: