precursor 0.4.0 → 0.5.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: e106154712ad13288b622f2c6fcdded80b583a68387c259f136d1b0c448fdfe0
4
- data.tar.gz: c99dc664e48950a6d6de38a0bd7f56c257f505d6065337f57c7d6021adc086e1
3
+ metadata.gz: bba5bce81c5c7e1d955c9f5c0acb4cf3898a5512f8fd66c1378469e6afe38081
4
+ data.tar.gz: 41f71f5e7a582aa678c1a62c5e453c31416de9d10706270b69cbae031ba98299
5
5
  SHA512:
6
- metadata.gz: 405695b440d4202e2c1a0678a92d5f17bb63fe9404774cf0f9d33dfff20c6c2c64322cfccd90f61bb06894325ea4edd3633dc08d71698459950b5aa37827cd08
7
- data.tar.gz: 7b843d26c18872d5174ae6fef796ffaf63c2deaeec4726d0948a5a2a18181748942757066949e9633edaa78657b11fc69bf14baf0b6db9d4c624615ddee802b9
6
+ metadata.gz: 14d9ed609d3b9d5322fa42da86698b5e6e7eab865c8c190aafc69a10d76f2c47f6be3667281dd9847a1549ec7cb5c41dbaebd3ede2de5e095d3c47e69394c997
7
+ data.tar.gz: 4b6ec72589f67c6f701e49ec026a7dfc14208ee0632c5d23d25adff565502e3decd51b98ff37db6cd12544bd039441e532b776f42795ef9f19e04330feafe23e
data/lib/config_root.rb CHANGED
@@ -24,7 +24,25 @@ module Precursor
24
24
  end
25
25
 
26
26
  raise KeyError, "key #{key} not found" unless found
27
+
28
+ value = resolve_variables(value) if value.is_a? String
29
+
27
30
  value
28
31
  end
32
+
33
+ private
34
+
35
+ VAR_PATTERN = /\$\{(?<var_name>[a-zA-Z]+[\w.]+)\}/
36
+ MAX_DEPTH = 16
37
+
38
+ def resolve_variables(str)
39
+ res = str
40
+ until (m = res.match(VAR_PATTERN)).nil?
41
+ k = m[1]
42
+ v = self[k.to_sym]
43
+ res = res.sub("${#{k}}", v.to_s)
44
+ end
45
+ res
46
+ end
29
47
  end
30
48
  end
data/lib/hash_vault.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'vault'
4
+
5
+ module Precursor
6
+ class HashVault < Vault
7
+ def initialize(hash)
8
+ @store = hash
9
+ end
10
+
11
+ protected
12
+
13
+ attr_reader :store
14
+ end
15
+ end
data/lib/precursor.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'config_root_builder'
4
4
 
5
5
  require_relative 'argv_vault'
6
6
  require_relative 'env_vault'
7
+ require_relative 'hash_vault'
7
8
  require_relative 'override_vault'
8
9
  require_relative 'thread_local_override_vault'
9
10
  require_relative 'yaml_vault'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Precursor
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: precursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Maraev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optparse
@@ -50,6 +50,7 @@ files:
50
50
  - lib/config_root.rb
51
51
  - lib/config_root_builder.rb
52
52
  - lib/env_vault.rb
53
+ - lib/hash_vault.rb
53
54
  - lib/override_vault.rb
54
55
  - lib/precursor.rb
55
56
  - lib/thread_local_override_vault.rb