precursor 0.5.1 → 0.6.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: 0e3304cac9ee21759234bd745095460b9dc71573f4cb6a0f54ba8ca7862c0b0a
4
- data.tar.gz: b1995f5395d1b767e08d61db569c40995b277f69f4b516646fed026a000acdb6
3
+ metadata.gz: 86985495bc3e48757e33837b70e20bd1a431f5e19ce750dd8a38cc6512ed0ffd
4
+ data.tar.gz: fecd720458ce41d39b8f000754500b0ebb9fc586a4cd7bf869657cc3b22391ec
5
5
  SHA512:
6
- metadata.gz: 4b3bb038529d96de309c2cf16e7acf1918310944612bd002dfa272e612c2a584c42fdea929cfe1a06f19999dc7b01b4f805c607891cbfb2621eebdd11a3724b6
7
- data.tar.gz: d73549d136b50202dd4b222a4e0145851ba78927f3677e9ff55259057a8599018e1494cee40941c7ceafdff745d79f41447aad01f7d7b13c2d1867bad7fc0a6d
6
+ metadata.gz: c582c2744224ddfb04b89eddfe0193bbb4b17ff789db6b3a1c56905806f3f769d1bbb3efe9f3f1e9211d1a0693cc262ca915991ea6ec3f5911ffa6df74ae5b41
7
+ data.tar.gz: 01e5f3bade8c2b1c16d7e630b299984a1abd5a752bf60a7ab0b2f2b0726e7fdb14709a5eeb23a5027587b663995fa1891afc4e3654aba3cea0b6dec8158a39c3
data/lib/argv_vault.rb CHANGED
@@ -10,8 +10,8 @@ require_relative 'vault'
10
10
  module Precursor
11
11
  # Vault that parses command line arguments
12
12
  class ArgvVault < Vault
13
- def initialize(argv)
14
- super()
13
+ def initialize(argv, priority:)
14
+ super(priority: priority)
15
15
 
16
16
  @vault_data = {}
17
17
  @parser = OptionParser.new do |parser|
data/lib/config_root.rb CHANGED
@@ -4,7 +4,7 @@ module Precursor
4
4
  # Root class to access config vaults
5
5
  class ConfigRoot
6
6
  def initialize(vaults, key_options)
7
- @vaults = vaults
7
+ @vaults = vaults.sort_by(&:priority).reverse
8
8
  @key_options = key_options
9
9
  end
10
10
 
@@ -17,6 +17,10 @@ module Precursor
17
17
  value.is_a?(String) ? resolve_variables(value) : value
18
18
  end
19
19
 
20
+ def add_vault(vault)
21
+ @vaults = @vaults.push(vault).sort_by(&:priority).reverse
22
+ end
23
+
20
24
  private
21
25
 
22
26
  VAR_PATTERN = /\$\{(?<var_name>[a-zA-Z]+[\w.]+)\}/
data/lib/env_vault.rb CHANGED
@@ -8,8 +8,8 @@ module Precursor
8
8
  # Initializes new instance of [EnvVault]
9
9
  # @param separator [String] separator for hierarchical config entries
10
10
  # @param allow_list [Array<String>] list of allowed env vars to prevent leaking of sensitive or unrelated vars
11
- def initialize(separator: '__', allow_list: [])
12
- super()
11
+ def initialize(priority:, separator: '__', allow_list: [])
12
+ super(priority: priority)
13
13
  @separator = separator
14
14
 
15
15
  allow_set = Set.new(allow_list)
data/lib/hash_vault.rb CHANGED
@@ -5,8 +5,8 @@ require_relative 'vault'
5
5
  module Precursor
6
6
  # Vault that reads config data from passed hash
7
7
  class HashVault < Vault
8
- def initialize(hash)
9
- super()
8
+ def initialize(hash, priority:)
9
+ super(priority: priority)
10
10
  @store = hash
11
11
  end
12
12
 
@@ -5,8 +5,8 @@ require_relative 'vault'
5
5
  module Precursor
6
6
  # Vault that stores data in hash and allows to override config on the fly
7
7
  class OverrideVault < Vault
8
- def initialize
9
- super()
8
+ def initialize(priority:)
9
+ super(priority: priority)
10
10
  @vault_data = {}
11
11
  end
12
12
 
data/lib/vault.rb CHANGED
@@ -3,6 +3,15 @@
3
3
  module Precursor
4
4
  # Base class for config vaults
5
5
  class Vault
6
+ # Priority of the vault. Vaults with higher priority are checked first when looking for config value
7
+ attr_reader :priority
8
+
9
+ # Initializes new instance of [Precursor::Vault]
10
+ # @param priority [Integer] the vault priority
11
+ def initialize(priority:)
12
+ @priority = priority
13
+ end
14
+
6
15
  # Returns true if the vault has a value for the given key, otherwise false
7
16
  # @return [Boolean] true if the vault has a value for the given key, otherwise false
8
17
  def key?(key)
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Precursor
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/yaml_vault.rb CHANGED
@@ -7,8 +7,8 @@ require_relative 'vault'
7
7
  module Precursor
8
8
  # Vault that reads config data from a string with Yaml
9
9
  class YamlVault < Vault
10
- def initialize(src)
11
- super()
10
+ def initialize(src, priority:)
11
+ super(priority: priority)
12
12
  @yaml = flat_hash(YAML.safe_load(src))
13
13
  end
14
14
 
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.5.1
4
+ version: 0.6.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-15 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optparse
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: code-scanning-rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: debug
29
43
  requirement: !ruby/object:Gem::Requirement