Class: Sumo::Config
Overview
This class contains the logic to find the user’s credentials from a configuration file. By default, the file is ‘~/.sumo_creds`.
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
Instance Method Summary collapse
-
#initialize(config_file = Sumo::CONFIG_FILE) ⇒ Config
constructor
Given an optional ‘String`, sets and freezes the `@config_file` instance variable, as long as it’s a valid file path.
-
#load_creds ⇒ Object
Load the credentials, returning nil if an error occurs.
-
#load_creds! ⇒ Object
Load the credentials, raising an any errors that occur.
Constructor Details
#initialize(config_file = Sumo::CONFIG_FILE) ⇒ Config
Given an optional ‘String`, sets and freezes the `@config_file` instance variable, as long as it’s a valid file path.
10 11 12 |
# File 'lib/sumo/config.rb', line 10 def initialize(config_file = Sumo::CONFIG_FILE) @config_file = File.(config_file).freeze end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
6 7 8 |
# File 'lib/sumo/config.rb', line 6 def config_file @config_file end |
Instance Method Details
#load_creds ⇒ Object
Load the credentials, returning nil if an error occurs.
22 23 24 |
# File 'lib/sumo/config.rb', line 22 def load_creds load_creds! rescue nil end |
#load_creds! ⇒ Object
Load the credentials, raising an any errors that occur.
15 16 17 18 19 |
# File 'lib/sumo/config.rb', line 15 def load_creds! @creds ||= load_file[cred_key].tap do |creds| raise NoCredsFound, "#{cred_key} not found in #{config_file}" if !creds end end |