class FallCli::Configuration

This is the configuration object. It reads in configuration from a .fallcli file located in the user’s home directory

Constants

FILE_NAME

Attributes

data[R]
path[R]

Public Class Methods

new() click to toggle source
# File lib/fallcli/config.rb, line 15
def initialize
  @path = ENV["FALLCLI_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME)
  @data = self.load_config_file
end

Public Instance Methods

app_key() click to toggle source
# File lib/fallcli/config.rb, line 29
def app_key
  @data['authentication']['app_key']
end
app_secret() click to toggle source
# File lib/fallcli/config.rb, line 41
def app_secret
  @data['client']['app_secret']
end
app_token() click to toggle source
# File lib/fallcli/config.rb, line 37
def app_token
  @data['client']['app_token']
end
create_config_file(app_key, secret_key, app_token, app_secret) click to toggle source

Writes a config file

# File lib/fallcli/config.rb, line 56
def create_config_file(app_key, secret_key, app_token, app_secret)
  FileUtils.mkdir_p File.join(File.expand_path("~"),'.fallcli/')
  require 'yaml'
  File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
    data = {
      "authentication" => { "app_key" => app_key, "secret_key" => secret_key },
      "client" => { "app_token" => app_token, "app_secret" => app_secret }
    }
    file.write data.to_yaml
  end
end
load_config_file() click to toggle source

If we can’t load the config file, self.data is nil, which we can check for in CheckConfiguration

# File lib/fallcli/config.rb, line 22
def load_config_file
  require 'yaml'
  YAML.load_file(@path)
rescue Errno::ENOENT
  return
end
reload!() click to toggle source

Re-loads the config

# File lib/fallcli/config.rb, line 51
def reload!
  @data = self.load_config_file
end
reset!() click to toggle source

Re-runs initialize

# File lib/fallcli/config.rb, line 46
def reset!
  self.send(:initialize)
end
secret_key() click to toggle source
# File lib/fallcli/config.rb, line 33
def secret_key
  @data['authentication']['secret_key']
end