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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c17af78afd9307b68d06babe18dad864243b49cc
4
- data.tar.gz: 9a5308abf16ccbce6be3d4990299f0e98912fdd0
3
+ metadata.gz: f09e214d197378f18e8573fa1ad516ed9d1bb178
4
+ data.tar.gz: cdd5f570d25b5f353537e1858de1f36d883ccd36
5
5
  SHA512:
6
- metadata.gz: f501e625f4623dcfc6d5df42a970d94de78ea4a2940ac61460595d4cff84524083eb0ffbbfebeb70ec0ed16bd8f5ea53321604661a7aab99f745006c6a9ab445
7
- data.tar.gz: eabe54c4414169478697f0b35bcb18c5adc0bf7e856a4e51ac54dc75cd41f8027d9e6aed70631c71a169cded64b149394b921a80d23d9d823c16ace82c3ee0de
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
- super(key.to_s) || super(key.to_sym)
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
- super(nil)
14
- else
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
- super(key) || super(key.to_s) || super(key.to_sym)
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
@@ -1,7 +1,6 @@
1
1
  module Opto
2
2
  module Extension
3
- # Refines String to have .snakecase method that turns
4
- # StringLikeThis into a string_like_this
3
+ # Refines hash to have #symbolize_keys which symbolizes all keys.
5
4
  module SymbolizeKeys
6
5
  refine Hash do
7
6
  def symbolize_keys
@@ -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
- val = ENV[hint.to_s]
13
- return nil if val.nil?
14
- case val
15
- when /\A\d+\z/ then val.to_i
16
- when /\Atrue\z/ then true
17
- when /\Afalse\z/ then false
18
- when /\A(?:null|nil)\z/ then nil
19
- else val
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?(Fixnum)
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."
@@ -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?(Fixnum) ? options[:true] : 1) : (options[:false].kind_of?(Fixnum) ? options[:false] : 0)
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
@@ -84,7 +84,7 @@ module Opto
84
84
  end
85
85
  end
86
86
  options
87
- when ::String, Fixnum
87
+ when ::String, ( 0.class == Integer ? Integer : Fixnum )
88
88
  options.map do |opt|
89
89
  { value: opt, description: opt, label: opt }
90
90
  end
@@ -1,3 +1,3 @@
1
1
  module Opto
2
- VERSION = "1.8.4"
2
+ VERSION = "1.8.5"
3
3
  end
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
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-03-07 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler