precursor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/argv_vault.rb +73 -0
- data/lib/env_vault.rb +3 -5
- data/lib/override_vault.rb +25 -0
- data/lib/precursor.rb +3 -0
- data/lib/thread_local_override_vault.rb +13 -0
- data/lib/vault.rb +9 -3
- data/lib/version.rb +1 -1
- data/lib/yaml_vault.rb +3 -5
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e106154712ad13288b622f2c6fcdded80b583a68387c259f136d1b0c448fdfe0
|
4
|
+
data.tar.gz: c99dc664e48950a6d6de38a0bd7f56c257f505d6065337f57c7d6021adc086e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 405695b440d4202e2c1a0678a92d5f17bb63fe9404774cf0f9d33dfff20c6c2c64322cfccd90f61bb06894325ea4edd3633dc08d71698459950b5aa37827cd08
|
7
|
+
data.tar.gz: 7b843d26c18872d5174ae6fef796ffaf63c2deaeec4726d0948a5a2a18181748942757066949e9633edaa78657b11fc69bf14baf0b6db9d4c624615ddee802b9
|
data/lib/argv_vault.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'optparse/date'
|
5
|
+
require 'optparse/time'
|
6
|
+
require 'optparse/uri'
|
7
|
+
|
8
|
+
require_relative 'vault'
|
9
|
+
|
10
|
+
module Precursor
|
11
|
+
# Vault that parses command line arguments
|
12
|
+
class ArgvVault < Vault
|
13
|
+
def initialize(argv)
|
14
|
+
@vault_data = {}
|
15
|
+
@parser = OptionParser.new do |parser|
|
16
|
+
parser.on('-h', '--help', 'Prints this help') do
|
17
|
+
puts parser
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
yield self
|
22
|
+
@parser.parse(argv)
|
23
|
+
end
|
24
|
+
|
25
|
+
def key(key_name)
|
26
|
+
builder = ArgvKeyBuilder.new(key_name)
|
27
|
+
yield builder
|
28
|
+
builder.build(@parser, @vault_data)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def store
|
34
|
+
@vault_data
|
35
|
+
end
|
36
|
+
|
37
|
+
class ArgvKeyBuilder
|
38
|
+
def initialize(key_name)
|
39
|
+
@key_name = key_name
|
40
|
+
@short = []
|
41
|
+
@long = []
|
42
|
+
@type = nil
|
43
|
+
@description = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def short(short_key)
|
47
|
+
@short.push(short_key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def long(long_key)
|
51
|
+
@long.push(long_key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def type(type)
|
55
|
+
@type = type
|
56
|
+
end
|
57
|
+
|
58
|
+
def description(desc)
|
59
|
+
@description = desc
|
60
|
+
end
|
61
|
+
|
62
|
+
def build(parser, vault_data)
|
63
|
+
args = @short + @long
|
64
|
+
args.push(@type) unless @type.nil?
|
65
|
+
args.push(@description) unless @description.nil?
|
66
|
+
|
67
|
+
parser.on(*args) do |v|
|
68
|
+
vault_data[@key_name] = v
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/env_vault.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'vault'
|
4
|
+
|
5
|
+
module Precursor
|
6
|
+
class OverrideVault < Vault
|
7
|
+
def initialize
|
8
|
+
@vault_data = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def override(key, value)
|
12
|
+
store[key] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear(key)
|
16
|
+
store.delete(key)
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def store
|
22
|
+
@vault_data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/precursor.rb
CHANGED
data/lib/vault.rb
CHANGED
@@ -5,14 +5,20 @@ module Precursor
|
|
5
5
|
class Vault
|
6
6
|
# Returns true if the vault has a value for the given key, otherwise false
|
7
7
|
# @return [Boolean] true if the vault has a value for the given key, otherwise false
|
8
|
-
def key?
|
9
|
-
|
8
|
+
def key?(key)
|
9
|
+
store.key?(key)
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns a value fot the given key, nil if key is not available
|
13
13
|
# @return [Object|Nil] a value for the given key
|
14
14
|
def value(key)
|
15
|
-
|
15
|
+
store[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
# Replace this method in descendant classes to return Hash-like store
|
20
|
+
def store
|
21
|
+
{}
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/version.rb
CHANGED
data/lib/yaml_vault.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: precursor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: optparse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: debug
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,11 +45,14 @@ executables: []
|
|
31
45
|
extensions: []
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
48
|
+
- lib/argv_vault.rb
|
34
49
|
- lib/config_key_builder.rb
|
35
50
|
- lib/config_root.rb
|
36
51
|
- lib/config_root_builder.rb
|
37
52
|
- lib/env_vault.rb
|
53
|
+
- lib/override_vault.rb
|
38
54
|
- lib/precursor.rb
|
55
|
+
- lib/thread_local_override_vault.rb
|
39
56
|
- lib/vault.rb
|
40
57
|
- lib/version.rb
|
41
58
|
- lib/yaml_vault.rb
|