Class: Sumo::Config

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/sumo/config.rb

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

Instance Method Summary collapse

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.expand_path(config_file).freeze
end

Instance Attribute Details

#config_fileObject (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_credsObject

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