dsl_factory 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9110073c0a21c89089537a09c4f21394b30fffa76aeaec2291c9918d58051479
4
- data.tar.gz: 06d23515ae9d3a03da213d7e6642ffe19cb7deba898e05526af11131070e644b
3
+ metadata.gz: e9c3690034afd5fcc2eef0bb823f898bd6182effa13a49f0dd26ba0ff4dc2769
4
+ data.tar.gz: 468b23fb9a0987109e4cf6deb00317cd8708b2984b88750dc0e1455dfd55d697
5
5
  SHA512:
6
- metadata.gz: 37b94876fd1631ab2247da8688cf5d8ded60282bcd204bec006a3017d7e843015b926aceb4a9237a0c85dc9fdfaa4641a3256709e23950dae1f4fc5103f926f3
7
- data.tar.gz: 2844d3bd1abd55906099d5a309276a8dfd180e10a7bfe6b48422c1a931f26cb79cdf8ac1b593e355e4851cfe809f6288463f183da8f029cf072b8aad0f7c1c16
6
+ metadata.gz: 41eec163f9c946cf7ab00bd1979079fdcb8c347154976c626219cd9f9956602efa339d52e97431add2900eda2c44e727546734115a2bc6af9cd1f6826beb37e8
7
+ data.tar.gz: fd6a86dc150ba55196d0c0d7a5cde2148628b9a9c90527544c063126b464d4cc1bd5d305c518805139a0c27c90cf8d9f88af567f691aca84f473f5e90ae4f00b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-08-23
4
+
5
+ - provide `inspect` method for better inspectability
6
+
3
7
  ## [0.1.0] - 2022-03-01
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dsl_factory (0.1.0)
4
+ dsl_factory (0.2.0)
5
5
  activesupport (>= 5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -101,8 +101,8 @@ class World
101
101
  country_size 'Germany', 357_022
102
102
  end
103
103
 
104
- SmartyPants.capital_for_countries # => { 'Berlin' => 'Germany', 'Copenhagen' => 'Denmark'}
105
- SmartyPants.country_sizes # => { 'Germany' => 357022 }
104
+ World.capital_for_countries # => { 'Berlin' => 'Germany', 'Copenhagen' => 'Denmark'}
105
+ World.country_sizes # => { 'Germany' => 357022 }
106
106
  ```
107
107
 
108
108
  **Nested DSLs**
@@ -148,13 +148,14 @@ ButtonDsl = DslFactory.define_dsl do
148
148
  # all types outlined above support callbacks
149
149
  any :trigger, callback: ->(value) { puts "#{value} was triggered" }
150
150
  any :snicker, callback: ->(value) { arg1, arg2 = value; puts "snicker: #{arg1} & #{arg2}" } # we can pass arguments via the value
151
- any :clicker, callback: ->(value) { self.do_the_click }
151
+ any :clicker, callback: ->(value) { self.do_the_click } # see method definition in using class
152
+ numeric :width, callback: ->(value) { raise DslFactory::ValidationError, 'buttons must be small' if width > 100 }
152
153
 
153
154
  # for arrays the callback always receives an array (even if it was used in singular form)
154
155
  # for hashes the callback receives two arguments: key, value
155
156
  end
156
157
 
157
- class Sabine
158
+ class MonsterButton
158
159
  extend ButtonDsl
159
160
  # if we want to call a method of the class, we need to define it before the first usage of the DSL method
160
161
  def self.do_the_click
@@ -163,10 +164,19 @@ class Sabine
163
164
 
164
165
  trigger 'abc' # -> abc was triggered
165
166
  snicker ['haha', 'hihi'] # -> snicker: haha & hihi
166
- clicker nil # make sure to alway pass a value, -> Click!
167
+ clicker nil # make sure to alway pass a value; -> Click!
168
+ width 2000 # -> DslFactory::ValidationError: buttons must be small
167
169
  end
170
+
171
+ MonsterButton.trigger # values are still set; => 'abc'
168
172
  ```
169
173
 
174
+ **Inspection**
175
+
176
+ For debugging it is useful to introspect the DSL values.
177
+ When `inspectable` is set to `true` (`DslFactory.define_dsl(inspectable: true)`) the module will provide an `inspect` method.
178
+ All sub-DSL modules provide an such a method by default.
179
+
170
180
  ## Use of the definition
171
181
 
172
182
  Usually we **extend a class** like so:
@@ -180,7 +190,7 @@ end
180
190
  LakeSuperior.lake_name # => 'Lake Superior'
181
191
  ```
182
192
 
183
- However we can also the **DSL in a variable**:
193
+ However we can also use the **DSL in a variable**:
184
194
 
185
195
  ```ruby
186
196
  @config = Module.new.extend(LakeDsl)
@@ -202,6 +212,14 @@ end
202
212
 
203
213
  ```
204
214
 
215
+ # Compatibility
216
+
217
+ The gem was/is used in production with the following Ruby versions:
218
+
219
+ - ✅ Ruby 2.7
220
+ - ✅ Ruby 3.0
221
+ - ✅ Ruby 3.1
222
+
205
223
  # Development
206
224
 
207
225
  ```bash
@@ -210,7 +228,7 @@ bundle install
210
228
  rake test # run the tests
211
229
  pry # require_relative 'lib/dsl_factory.rb'
212
230
 
213
- # to release a new version, update the version number in `version.rb`, then run
231
+ # to release a new version, update `CHANGELOG.md` and the version number in `version.rb`, then run
214
232
  bundle exec rake release
215
233
  ```
216
234
 
@@ -15,6 +15,12 @@ class DslFactory::Generator
15
15
  end
16
16
  end
17
17
 
18
+ def define_inspect
19
+ @definition.define_method(:inspect) do
20
+ "DSL#{@dsl_values.inspect}"
21
+ end
22
+ end
23
+
18
24
  # for more information & examples, please see README.md
19
25
  #
20
26
  # if a `callback` is given it will be called when the extended class uses this attribute (after setting the value).
@@ -70,7 +76,7 @@ class DslFactory::Generator
70
76
 
71
77
  if block # we deal with a sub-DSL
72
78
  value_object = Class.new
73
- value_object.extend(DslFactory.define_dsl(&definition_block))
79
+ value_object.extend(DslFactory.define_dsl(inspectable: true, &definition_block))
74
80
  value_object.instance_eval(&block)
75
81
  value = value_object
76
82
  end
@@ -97,7 +103,7 @@ class DslFactory::Generator
97
103
 
98
104
  if block # we deal with a sub-DSL
99
105
  value_object = Class.new
100
- value_object.extend(DslFactory.define_dsl(&definition_block))
106
+ value_object.extend(DslFactory.define_dsl(inspectable: true, &definition_block))
101
107
  value_object.instance_eval(&block)
102
108
  value = value_object
103
109
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DslFactory
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/dsl_factory.rb CHANGED
@@ -7,8 +7,9 @@ module DslFactory
7
7
  class DefinitionError < StandardError; end
8
8
  class ValidationError < StandardError; end
9
9
 
10
- def define_dsl(&block)
10
+ def define_dsl(inspectable: false, &block)
11
11
  generator = DslFactory::Generator.new
12
+ generator.define_inspect if inspectable
12
13
  generator.instance_eval(&block)
13
14
  return generator.definition
14
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsl_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Rothe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -50,7 +50,7 @@ metadata:
50
50
  homepage_uri: https://github.com/motine/dsl_factory
51
51
  source_code_uri: https://github.com/motine/dsl_factory
52
52
  changelog_uri: https://github.com/motine/dsl_factory/blob/master/CHANGELOG.md
53
- post_install_message:
53
+ post_install_message:
54
54
  rdoc_options: []
55
55
  require_paths:
56
56
  - lib
@@ -65,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.2.15
69
- signing_key:
68
+ rubygems_version: 3.1.6
69
+ signing_key:
70
70
  specification_version: 4
71
71
  summary: A small DSL to generate DSLs
72
72
  test_files: []