Class: EacRubyUtils::Console::Configs
- Includes:
- Speaker
- Defined in:
- lib/eac_ruby_utils/console/configs.rb
Constant Summary collapse
- STORE_PASSWORDS_KEY =
'core.store_passwords'
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
Instance Method Summary collapse
-
#initialize(configs_key) ⇒ Configs
constructor
A new instance of Configs.
- #read_entry(entry_key, options = {}) ⇒ Object
- #request_password(entry_key, options = {}) ⇒ Object
- #store_passwords? ⇒ Boolean
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
#configs ⇒ Object (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, = {}) stored_value = configs.read_entry(entry_key) return stored_value if stored_value [:before_input].call if [:before_input].present? entry_value = looped_entry_value_from_input(entry_key, ) 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, = {}) = .merge(noecho: true) if store_passwords? read_entry(entry_key, ) else looped_entry_value_from_input(entry_key, ) end end |
#store_passwords? ⇒ 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: -> { }, validator: ->(entry_value) { %w[yes no].include?(entry_value) } ) end |