Class: EacRubyUtils::Console::Configs
- Includes:
- Speaker
- Defined in:
- lib/eac_ruby_utils/console/configs.rb
Defined Under Namespace
Classes: ReadEntryOptions
Constant Summary collapse
- STORE_PASSWORDS_KEY =
'core.store_passwords'
Constants included from Speaker
Speaker::STDERR, Speaker::STDIN, Speaker::STDOUT
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(configs_key, options = {}) ⇒ Configs
constructor
A new instance of Configs.
- #read_entry(entry_key, options = {}) ⇒ Object
- #read_password(entry_key, options = {}) ⇒ Object
- #store_passwords? ⇒ Boolean
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
Returns a new instance of Configs.
31 32 33 34 |
# File 'lib/eac_ruby_utils/console/configs.rb', line 31 def initialize(configs_key, = {}) .assert_argument(::Hash, 'options') @configs = ::EacRubyUtils::Configs.new(configs_key, .merge(autosave: true)) end |
Instance Attribute Details
#configs ⇒ Object (readonly)
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, = {}) = ReadEntryOptions.new() unless [: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, ) unless [:noinput] raise "No value found for entry \"#{entry_key}\"" if [: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, = {}) = .merge(noecho: true) if store_passwords? read_entry(entry_key, ) else looped_entry_value_from_input(entry_key, ) 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: -> { }, validator: ->(entry_value) { %w[yes no].include?(entry_value) } ) == 'yes' end |