Class: EacRubyUtils::Console::Configs

Inherits:
Object
  • Object
show all
Includes:
Speaker
Defined in:
lib/eac_ruby_utils/console/configs.rb

Constant Summary collapse

STORE_PASSWORDS_KEY =
'core.store_passwords'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Speaker

#fatal_error, #info, #infom, #infov, #out, #puts, #request_input, #success, #title, #warn

Constructor Details

#initialize(configs_key) ⇒ Configs

Returns a new instance of Configs.



15
16
17
# File 'lib/eac_ruby_utils/console/configs.rb', line 15

def initialize(configs_key)
  @configs = ::EacRubyUtils::Configs.new(configs_key, autosave: true)
end

Instance Attribute Details

#configsObject (readonly)

Returns the value of attribute configs.



13
14
15
# File 'lib/eac_ruby_utils/console/configs.rb', line 13

def configs
  @configs
end

Instance Method Details

#read_entry(entry_key, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/eac_ruby_utils/console/configs.rb', line 28

def read_entry(entry_key, options = {})
  stored_value = configs.read_entry(entry_key)
  return stored_value if stored_value
  options[:before_input].call if options[:before_input].present?
  entry_value = looped_entry_value_from_input(entry_key, options)
  configs.write_entry(entry_key, entry_value)
  entry_value
end

#request_password(entry_key, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/eac_ruby_utils/console/configs.rb', line 19

def request_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

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/eac_ruby_utils/console/configs.rb', line 37

def store_passwords?
  'yes' == read_entry(
    STORE_PASSWORDS_KEY,
    before_input: -> { store_password_banner },
    validator: ->(entry_value) { %w[yes no].include?(entry_value) }
  )
end