eac_config 0.5.2 → 0.8.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: f849abc9e1add60abdeb04359a38568809a240839eb68fbe6a69c298179713cf
4
- data.tar.gz: 9f9fdc2e7afc1143273b22c3267143c35f307dabcebee01a03b7c82cde2e232c
3
+ metadata.gz: 1a03da4e24715d7384e6de3cd61bb33bf9d1668234675059be4afb39355d82e1
4
+ data.tar.gz: 0f97dd63aae43cb52748f17ce8bc15488a11eaaa0ff65ccf2b15b0ee0ef0b16e
5
5
  SHA512:
6
- metadata.gz: e2c40d3aeab688ecd2f85225cbafe9023a7bbd17d645d28608d6de12ff439aebd0fcfdd107da925082410b996c65a3930bcc1035e77e8a6c3b500fe5a4ed8816
7
- data.tar.gz: 403bc52ef8019a834eada038392cb2a91ae2d09530b35f5fa966946972855cbfd5744317347bb890550a7302fc0ea347a95c0dc2692786c86f1597c6b7a8f991
6
+ metadata.gz: 91b13a3a78a6fc3029584d1942d4977beea8d7c213ac9a56721cd3aae15a8492c3491bd9d7a33f095049f8389d165322949750121c70dffdc114af8a753b540d
7
+ data.tar.gz: 060bd6ef9c82bfc29418e16ea2985bc120a5e2759e7ae2dc787b683d6d912818207417694bdb26b345e5a1298a8915006a6541f8fa51c70c437be7de48770d3e
@@ -18,6 +18,10 @@ module EacConfig
18
18
  node_entry.if_present(&:node)
19
19
  end
20
20
 
21
+ def secret_value
22
+ node_entry.if_present(&:secret_value)
23
+ end
24
+
21
25
  def value
22
26
  node_entry.if_present(&:value)
23
27
  end
@@ -14,5 +14,9 @@ module EacConfig
14
14
  end
15
15
 
16
16
  abstract_methods :found?, :value, :value=
17
+
18
+ def secret_value
19
+ value
20
+ end
17
21
  end
18
22
  end
@@ -49,6 +49,13 @@ module EacConfig
49
49
 
50
50
  delegate :to_h, to: :root
51
51
 
52
+ # @return [EacConfig::PathsHash
53
+ def write(entry_key, entry_value)
54
+ self[entry_key] = entry_value
55
+
56
+ self
57
+ end
58
+
52
59
  private
53
60
 
54
61
  attr_reader :data
@@ -1,17 +1,64 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/temp'
4
5
  require 'eac_config/envvars_node'
6
+ require 'eac_config/node'
7
+ require 'eac_config/yaml_file_node'
5
8
 
6
9
  module EacConfig
7
10
  module Rspec
8
11
  module Setup
9
12
  def self.extended(obj)
10
- obj.clean_envvars_load_path
13
+ obj.rspec_config.around do |example|
14
+ obj.on_envvars_load_path_clean(example)
15
+ end
11
16
  end
12
17
 
13
- def clean_envvars_load_path
14
- ::EacConfig::EnvvarsNode.new.load_path.entry.value = []
18
+ def on_envvars_load_path_clean(example)
19
+ old_value = envvars_load_path_entry.value
20
+ begin
21
+ envvars_load_path_entry.value = old_value = []
22
+ example.run
23
+ ensure
24
+ envvars_load_path_entry.value = old_value
25
+ end
26
+ end
27
+
28
+ def envvars_load_path_entry
29
+ ::EacConfig::EnvvarsNode.new.load_path.entry
30
+ end
31
+
32
+ # Wraps a RSpec example in a EacConfig node using a alternative file.
33
+ #
34
+ # @param target_example [RSpec::Core::ExampleGroup] The example to wrap. If not provided,
35
+ # it is applied to all examples.
36
+ # @param target_file [Pathname] The file used by the EacConfig node. If not provided, a
37
+ # temporary file is used.
38
+ # @param node_builder [Proc] Should return the desired EacConfig node. If not provided, a
39
+ # EacConfig::YamlFileNode is created.
40
+ def stub_eac_config_node(target_example = nil, target_file = nil, &node_builder)
41
+ parent_self = self
42
+ (target_example || rspec_config).around do |example|
43
+ parent_self.stub_eac_config_node_on_file(target_file) do |file|
44
+ ::EacConfig::Node
45
+ .context.on(parent_self.stub_eac_config_node_build(file, &node_builder)) do
46
+ example.run
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def stub_eac_config_node_build(file, &node_builder)
53
+ node_builder.present? ? node_builder.call(file) : ::EacConfig::YamlFileNode.new(file)
54
+ end
55
+
56
+ def stub_eac_config_node_on_file(target_file)
57
+ if target_file
58
+ yield(target_file.to_pathname)
59
+ else
60
+ ::EacRubyUtils::Fs::Temp.on_file { |file| yield(file) }
61
+ end
15
62
  end
16
63
  end
17
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacConfig
4
- VERSION = '0.5.2'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -18,14 +18,13 @@ module EacConfig
18
18
  end
19
19
 
20
20
  def value=(a_value)
21
- paths_hash[to_paths_hash_key] = a_value
22
- node.persist_data(paths_hash.root.to_h)
21
+ node.persist_data(paths_hash.write(to_paths_hash_key, a_value).root.to_h)
23
22
  end
24
23
 
25
24
  private
26
25
 
27
26
  # @return [EacConfig::PathsHash]
28
- def paths_hash_uncached
27
+ def paths_hash
29
28
  ::EacConfig::PathsHash.new(node.data)
30
29
  end
31
30
 
@@ -9,6 +9,7 @@ module EacConfig
9
9
  class YamlFileNode
10
10
  require_sub __FILE__
11
11
  include ::EacConfig::Node
12
+ enable_simple_cache
12
13
 
13
14
  class << self
14
15
  def from_uri(uri)
@@ -20,14 +21,10 @@ module EacConfig
20
21
  self.path = path.to_pathname
21
22
  end
22
23
 
23
- def data
24
- @data ||= ::EacRubyUtils::Yaml.load_file(assert_path) || {}
25
- end
26
-
27
24
  def persist_data(new_data)
28
25
  path.parent.mkpath
29
26
  ::EacRubyUtils::Yaml.dump_file(path, new_data)
30
- @data = nil
27
+ reset_cache(:data)
31
28
  end
32
29
 
33
30
  def url
@@ -36,13 +33,15 @@ module EacConfig
36
33
 
37
34
  private
38
35
 
39
- def assert_path
40
- unless path.file?
41
- raise("\"#{path}\" is a not a file") if path.exist?
42
-
43
- persist_data({})
36
+ def data_uncached
37
+ r = nil
38
+ if path.file?
39
+ r = ::EacRubyUtils::Yaml.load_file(path)
40
+ elsif path.exist?
41
+ raise("\"#{path}\" is a not a file")
44
42
  end
45
- path
43
+
44
+ r.is_a?(::Hash) ? r : {}
46
45
  end
47
46
  end
48
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-04 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.70'
33
+ version: '0.83'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.70'
40
+ version: '0.83'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: eac_ruby_gem_support
43
43
  requirement: !ruby/object:Gem::Requirement