Class: AgentStatusBulb::Configure
- Inherits:
-
Object
- Object
- AgentStatusBulb::Configure
- Defined in:
- lib/agent_status_bulb/configure.rb
Constant Summary collapse
- DEFAULT_PATH =
File.('~/.config/agent_status_bulb.yml').freeze
- CREDENTIAL_FIELDS =
[ { key: :token, label: 'Token', conceal: true }, { key: :secret, label: 'Secret', conceal: true }, { key: :device_id, label: 'Device ID', conceal: false } ].freeze
Instance Method Summary collapse
- #configure! ⇒ Object
-
#initialize(path = DEFAULT_PATH) ⇒ Configure
constructor
A new instance of Configure.
- #load! ⇒ Object
Constructor Details
#initialize(path = DEFAULT_PATH) ⇒ Configure
Returns a new instance of Configure.
16 17 18 |
# File 'lib/agent_status_bulb/configure.rb', line 16 def initialize(path = DEFAULT_PATH) @path = path end |
Instance Method Details
#configure! ⇒ Object
20 21 22 23 24 |
# File 'lib/agent_status_bulb/configure.rb', line 20 def configure! credentials = gather_credentials write_config(credentials) $stdout.puts "Saved config to: #{@path}" end |
#load! ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/agent_status_bulb/configure.rb', line 26 def load! data = read_config CREDENTIAL_FIELDS.each_with_object({}) do |field, result| value = data.fetch(field[:key].to_s, '').to_s.strip raise missing_config_error if value.empty? result[field[:key]] = value end end |