fig_tree 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/fig_tree/version.rb +1 -1
- data/lib/fig_tree.rb +28 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2569e3b3e914e96bb517fe6a655c9b4b8bafc29ca50b37a31408b41c3b094860
|
4
|
+
data.tar.gz: 3d9cd4410eea8f55a91d1efeee3557b9633baa82f8c85a41a9ddcbbf7ce40fa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 146d732d5155ab2b25a40278b7372198e894a90aa148ebc05383ccbd3d08d5ac00a445c13152adf8c9f41afcb262b2df23eb586ca33fd547376f290e44ac5b7e
|
7
|
+
data.tar.gz: 508b13e81c6b588c76c3aed53b016e7e4b77e88960a7b8876e6b299bdf47a783be8704cf40745c5a9e68b6ab186b98ff16b9ab158bf8151fa7e724af8dd5bb03
|
data/CHANGELOG.md
CHANGED
data/lib/fig_tree/version.rb
CHANGED
data/lib/fig_tree.rb
CHANGED
@@ -241,6 +241,34 @@ module FigTree
|
|
241
241
|
@config ||= ConfigStruct.new('config')
|
242
242
|
end
|
243
243
|
|
244
|
+
# Evaluate a block with the given configuration values. Reset back to the original values
|
245
|
+
# when done.
|
246
|
+
# @param values [Hash]
|
247
|
+
def with_config(**values, &block) # rubocop:disable Metrics/AbcSize
|
248
|
+
set_value = lambda do |k, v|
|
249
|
+
obj = self.config
|
250
|
+
tokens = k.split('.')
|
251
|
+
tokens[0..-2].each do |token|
|
252
|
+
obj = obj.send(token)
|
253
|
+
end
|
254
|
+
obj.send(:"#{tokens.last}=", v)
|
255
|
+
end
|
256
|
+
|
257
|
+
get_value = lambda do |k|
|
258
|
+
obj = self.config
|
259
|
+
tokens = k.split('.')
|
260
|
+
tokens.each do |token|
|
261
|
+
obj = obj.send(token)
|
262
|
+
end
|
263
|
+
obj
|
264
|
+
end
|
265
|
+
|
266
|
+
old_values = values.keys.map { |k| [k, get_value.call(k)] }.to_h
|
267
|
+
values.each { |k, v| set_value.call(k, v) }
|
268
|
+
block.call
|
269
|
+
old_values.each { |k, v| set_value.call(k, v) }
|
270
|
+
end
|
271
|
+
|
244
272
|
# Pass a block to run after configuration is done.
|
245
273
|
def after_configure(&block)
|
246
274
|
mod = self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fig_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.3.7
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Configuration framework for Ruby.
|