Class: EacCli::OldConfigs::EntryReader
- Inherits:
-
Object
- Object
- EacCli::OldConfigs::EntryReader
show all
- Defined in:
- lib/eac_cli/old_configs/entry_reader.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.entry_key_to_envvar_name(entry_key) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/eac_cli/old_configs/entry_reader.rb', line 13
def entry_key_to_envvar_name(entry_key)
path = if entry_key.is_a?(::Array)
entry_key
else
::EacConfig::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
28
29
30
31
32
33
34
35
36
|
# File 'lib/eac_cli/old_configs/entry_reader.rb', line 28
def read
%w[envvars storage console].each do |suffix|
value = send("read_from_#{suffix}")
return value if value.present?
end
return nil unless options[:required]
raise "No value found for entry \"#{entry_key}\""
end
|
#read_from_console ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/eac_cli/old_configs/entry_reader.rb', line 51
def read_from_console
return if options[:noinput]
options[:before_input].if_present(&:call)
entry_value = looped_entry_value_from_input
console_configs.configs.write_entry(entry_key, entry_value) if options[:store]
entry_value
end
|
#read_from_envvars ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/eac_cli/old_configs/entry_reader.rb', line 42
def read_from_envvars
return if options[:noenv]
env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
return unless ENV.key?(env_entry_key)
ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
end
|
#read_from_storage ⇒ Object
38
39
40
|
# File 'lib/eac_cli/old_configs/entry_reader.rb', line 38
def read_from_storage
console_configs.configs.read_entry(entry_key)
end
|