Class: Slipsquare::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/slipsquare/config.rb

Overview

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

Constant Summary collapse

FILE_NAME =
'.slipsquare'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
# File 'lib/slipsquare/config.rb', line 14

def initialize
  @path = ENV["SLIPSTREAM_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME)
  @data = self.load_config_file
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/slipsquare/config.rb', line 9

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/slipsquare/config.rb', line 10

def path
  @path
end

Instance Method Details

#app_keyObject



28
29
30
# File 'lib/slipsquare/config.rb', line 28

def app_key
  @data['authentication']['app_key']
end

#app_secretObject



40
41
42
# File 'lib/slipsquare/config.rb', line 40

def app_secret
  @data['client']['app_secret']
end

#app_tokenObject



36
37
38
# File 'lib/slipsquare/config.rb', line 36

def app_token
  @data['client']['app_token']
end

#create_config_file(app_key, secret_key, app_token, app_secret) ⇒ Object

Writes a config file



55
56
57
58
59
60
61
62
63
64
# File 'lib/slipsquare/config.rb', line 55

def create_config_file(app_key, secret_key, app_token, app_secret)
  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_fileObject

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



21
22
23
24
25
26
# File 'lib/slipsquare/config.rb', line 21

def load_config_file
  require 'yaml'
  YAML.load_file(@path)
rescue Errno::ENOENT
  return
end

#reload!Object

Re-loads the config



50
51
52
# File 'lib/slipsquare/config.rb', line 50

def reload!
  @data = self.load_config_file
end

#reset!Object

Re-runs initialize



45
46
47
# File 'lib/slipsquare/config.rb', line 45

def reset!
  self.send(:initialize)
end

#secret_keyObject



32
33
34
# File 'lib/slipsquare/config.rb', line 32

def secret_key
  @data['authentication']['secret_key']
end