opto 1.8.4 → 1.8.5
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 +4 -4
- data/README.md +9 -0
- data/lib/opto/extensions/hash_string_or_symbol_key.rb +16 -7
- data/lib/opto/extensions/symbolize_keys.rb +1 -2
- data/lib/opto/group.rb +1 -3
- data/lib/opto/resolvers/environment_variable.rb +12 -8
- data/lib/opto/resolvers/random_string.rb +1 -1
- data/lib/opto/types/boolean.rb +1 -1
- data/lib/opto/types/enum.rb +1 -1
- data/lib/opto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f09e214d197378f18e8573fa1ad516ed9d1bb178
|
4
|
+
data.tar.gz: cdd5f570d25b5f353537e1858de1f36d883ccd36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a56379fd1e8d728367041daf2cd8a40f40e3ea5b7d0d46791e377e57cf987afd88861902464bca5d1c9321065c81db557caabf8a75a39beb891fffec3f2226e0
|
7
|
+
data.tar.gz: f90133ea4e15a9213ea16e9e82da3fae9f61693f54ca24ce7d389dae18424863ae2981db9487d6e1f71ca0ad89d6129f77a99fc6b69f40b7add8f7f113ff4664
|
data/README.md
CHANGED
@@ -465,6 +465,15 @@ Hint is the value that gets passed to the resolver when doing for example: `env:
|
|
465
465
|
### env
|
466
466
|
Hint is the environment variable name to read from. Defaults to the option's name.
|
467
467
|
|
468
|
+
To try multiple env variables, use:
|
469
|
+
|
470
|
+
```yaml
|
471
|
+
from:
|
472
|
+
env:
|
473
|
+
- KEY1
|
474
|
+
- KEY2
|
475
|
+
```
|
476
|
+
|
468
477
|
### file
|
469
478
|
Hint can be a string containing a path to the file, or a hash that defines `path: 'file_path', ignore_errors: true`
|
470
479
|
|
@@ -4,21 +4,30 @@ module Opto
|
|
4
4
|
module HashStringOrSymbolKey
|
5
5
|
refine Hash do
|
6
6
|
def [](key)
|
7
|
-
return nil if key.nil?
|
8
|
-
|
7
|
+
return super(nil) if key.nil?
|
8
|
+
|
9
|
+
[key, key.to_s, key.to_sym].each do |k|
|
10
|
+
val = super(k)
|
11
|
+
return val unless val.nil?
|
12
|
+
end
|
13
|
+
super(key)
|
9
14
|
end
|
10
15
|
|
11
16
|
def has_key?(key)
|
12
|
-
if key.nil?
|
13
|
-
|
14
|
-
|
15
|
-
super(key.to_s) || super(key.to_sym)
|
17
|
+
return super(nil) if key.nil?
|
18
|
+
[key, key.to_s, key.to_sym].each do |k|
|
19
|
+
return true if super(k)
|
16
20
|
end
|
21
|
+
false
|
17
22
|
end
|
18
23
|
|
19
24
|
def delete(key)
|
20
25
|
return nil if key.nil?
|
21
|
-
|
26
|
+
[key, key.to_s, key.to_sym].each do |k|
|
27
|
+
val = super(k)
|
28
|
+
return val unless val.nil?
|
29
|
+
end
|
30
|
+
nil
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/opto/group.rb
CHANGED
@@ -38,7 +38,6 @@ module Opto
|
|
38
38
|
else
|
39
39
|
@options = []
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
|
44
43
|
# Are all options valid? (Option value passes validation)
|
@@ -181,7 +180,6 @@ module Opto
|
|
181
180
|
end
|
182
181
|
end
|
183
182
|
|
184
|
-
|
185
|
-
def_delegators :@options, *(::Array.instance_methods - [:__send__, :object_id, :to_h, :to_a, :is_a?, :kind_of?, :instance_of?])
|
183
|
+
def_delegators :@options, *(::Array.instance_methods - [:__send__, :object_id, :to_h, :to_a, :is_a?, :kind_of?, :instance_of?, :self, :inspect, :nil?])
|
186
184
|
end
|
187
185
|
end
|
@@ -9,15 +9,19 @@ module Opto
|
|
9
9
|
|
10
10
|
def resolve
|
11
11
|
raise ArgumentError, "Environment variable name not set" if hint.nil?
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
Array(hint).each do |hint|
|
13
|
+
val = ENV[hint.to_s]
|
14
|
+
val = case val
|
15
|
+
when NilClass then nil
|
16
|
+
when /\A\d+\z/ then val.to_i
|
17
|
+
when /\Atrue\z/ then true
|
18
|
+
when /\Afalse\z/ then false
|
19
|
+
when /\A(?:null|nil)\z/ then nil
|
20
|
+
else val
|
21
|
+
end
|
22
|
+
return val unless val.nil?
|
20
23
|
end
|
24
|
+
nil
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -55,7 +55,7 @@ module Opto
|
|
55
55
|
if hint[:length].nil?
|
56
56
|
raise ArgumentError, "Invalid settings for random string. Required: length, optional: charset. Charsets : numbers, letters, alphanumeric, hex, base64, ascii_printable and X-Y range."
|
57
57
|
end
|
58
|
-
elsif (hint.kind_of?(String) && hint.to_i > 0) || hint.kind_of?(
|
58
|
+
elsif (hint.kind_of?(String) && hint.to_i > 0) || hint.kind_of?(0.class)
|
59
59
|
self.hint = { length: hint.to_i }
|
60
60
|
else
|
61
61
|
raise ArgumentError, "Missing settings for random string."
|
data/lib/opto/types/boolean.rb
CHANGED
@@ -44,7 +44,7 @@ module Opto
|
|
44
44
|
sanitizer :output do |value|
|
45
45
|
case options[:as].to_s.strip.downcase
|
46
46
|
when 'integer'
|
47
|
-
value ? (options[:true].kind_of?(
|
47
|
+
value ? (options[:true].kind_of?(0.class) ? options[:true] : 1) : (options[:false].kind_of?(Fixnum) ? options[:false] : 0)
|
48
48
|
when 'boolean'
|
49
49
|
value
|
50
50
|
else
|
data/lib/opto/types/enum.rb
CHANGED
data/lib/opto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimmo Lehto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|