Class: EacRubyUtils::Console::Configs
- Inherits:
-
Object
- Object
- EacRubyUtils::Console::Configs
show all
- Defined in:
- lib/eac_ruby_utils/console/configs.rb,
lib/eac_ruby_utils/console/configs/read_entry_options.rb
Defined Under Namespace
Classes: ReadEntryOptions
Constant Summary
collapse
- STORE_PASSWORDS_KEY =
'core.store_passwords'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configs_key, options = {}) ⇒ Configs
Returns a new instance of Configs.
28
29
30
31
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 28
def initialize(configs_key, options = {})
options.assert_argument(::Hash, 'options')
@configs = ::EacRubyUtils::Configs.new(configs_key, options.merge(autosave: true))
end
|
Instance Attribute Details
Returns the value of attribute configs.
26
27
28
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 26
def configs
@configs
end
|
Class Method Details
.entry_key_to_envvar_name(entry_key) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 13
def entry_key_to_envvar_name(entry_key)
path = if entry_key.is_a?(::Array)
entry_key
else
::EacRubyUtils::PathsHash.parse_entry_key(entry_key)
end
path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
.gsub(/_{2,}/, '_').upcase
end
|
Instance Method Details
#read_entry(entry_key, options = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 42
def read_entry(entry_key, options = {})
options = ReadEntryOptions.new(options)
unless options[:noenv]
envvar_value = envvar_read_entry(entry_key)
return envvar_value if envvar_value.present?
end
stored_value = configs.read_entry(entry_key)
return stored_value if stored_value
return read_entry_from_console(entry_key, options) unless options[:noinput]
raise "No value found for entry \"#{entry_key}\"" if options[:required]
end
|
#read_password(entry_key, options = {}) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 33
def read_password(entry_key, options = {})
options = ReadEntryOptions.new(options.merge(noecho: true))
if store_passwords?
read_entry(entry_key, options)
else
looped_entry_value_from_input(entry_key, options)
end
end
|
#store_passwords? ⇒ Boolean
55
56
57
58
59
60
61
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 55
def store_passwords?
read_entry(
STORE_PASSWORDS_KEY,
before_input: -> { store_password_banner },
validator: ->(entry_value) { %w[yes no].include?(entry_value) }
) == 'yes'
end
|