Class: Slipsquare::Configuration
- Inherits:
-
Object
- Object
- Slipsquare::Configuration
- 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
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #app_key ⇒ Object
- #app_secret ⇒ Object
- #app_token ⇒ Object
-
#create_config_file(app_key, secret_key, app_token, app_secret) ⇒ Object
Writes a config file.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_config_file ⇒ Object
If we can’t load the config file, self.data is nil, which we can check for in CheckConfiguration.
-
#reload! ⇒ Object
Re-loads the config.
-
#reset! ⇒ Object
Re-runs initialize.
- #secret_key ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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.("~"), FILE_NAME) @data = self.load_config_file end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/slipsquare/config.rb', line 9 def data @data end |
#path ⇒ Object (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_key ⇒ Object
28 29 30 |
# File 'lib/slipsquare/config.rb', line 28 def app_key @data['authentication']['app_key'] end |
#app_secret ⇒ Object
40 41 42 |
# File 'lib/slipsquare/config.rb', line 40 def app_secret @data['client']['app_secret'] end |
#app_token ⇒ Object
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_file ⇒ Object
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_key ⇒ Object
32 33 34 |
# File 'lib/slipsquare/config.rb', line 32 def secret_key @data['authentication']['secret_key'] end |