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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1587ecda3a1e2b8a7c1993a2503ac43a23f8a94f9bbcdb70c19b1824dd07549
4
- data.tar.gz: c90479e701fb69cd2c734e87fc7f111313677d461822a7cd222610ea15926ef5
3
+ metadata.gz: 2569e3b3e914e96bb517fe6a655c9b4b8bafc29ca50b37a31408b41c3b094860
4
+ data.tar.gz: 3d9cd4410eea8f55a91d1efeee3557b9633baa82f8c85a41a9ddcbbf7ce40fa3
5
5
  SHA512:
6
- metadata.gz: db355d8c2c40596245c6f68c5b99023bc372fa705c04f3936fd34ca55b34526539c2a87bb49afe545c075666c26caeb06264d792be064c5fd4f048fd405bb465
7
- data.tar.gz: 6366b0a1c6be5b66e98adc2bbab97449fe88ac5f102e84e6ae21828f6db7b3d6796b6e51d619b241514db5398bf342c26f04e23dbcbb25361dc60a3c211bc17e
6
+ metadata.gz: 146d732d5155ab2b25a40278b7372198e894a90aa148ebc05383ccbd3d08d5ac00a445c13152adf8c9f41afcb262b2df23eb586ca33fd547376f290e44ac5b7e
7
+ data.tar.gz: 508b13e81c6b588c76c3aed53b016e7e4b77e88960a7b8876e6b299bdf47a783be8704cf40745c5a9e68b6ab186b98ff16b9ab158bf8151fa7e724af8dd5bb03
data/CHANGELOG.md CHANGED
@@ -7,5 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## [0.0.3] - 2022-05-13
11
+ - Added `with_config` method for testing.
12
+
10
13
  ## [0.0.2] - 2021-02-17
11
14
  - Initial release.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FigTree
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
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.2
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: 2021-03-10 00:00:00.000000000 Z
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.2.3
169
+ rubygems_version: 3.3.7
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Configuration framework for Ruby.