Class: EacRubyUtils::Console::Configs
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
Methods included from Speaker
current_node, #fatal_error, #info, #infom, #infov, on_node, #on_speaker_node, #out, pop, push, #puts, #request_input, #success, #title, #warn
Constructor Details
#initialize(configs_key, options = {}) ⇒ Configs
31
32
33
34
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 31
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.
29
30
31
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 29
def configs
@configs
end
|
Class Method Details
.entry_key_to_envvar_name(entry_key) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 16
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
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 45
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
36
37
38
39
40
41
42
43
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 36
def read_password(entry_key, options = {})
options = 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
58
59
60
61
62
63
64
|
# File 'lib/eac_ruby_utils/console/configs.rb', line 58
def store_passwords?
read_entry(
STORE_PASSWORDS_KEY,
before_input: -> { store_password_banner },
validator: ->(entry_value) { %w[yes no].include?(entry_value) }
) == 'yes'
end
|