Class: Confinicky::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/confinicky/configuration_file.rb

Overview

A singleton model representing the configuration YAML utilized by Confinicky.

Constant Summary collapse

SUPPORTED_KEYS =
[:aliases, :env]
PATH =
Confinicky::Paths::CONFIG
@@configuration =
nil

Class Method Summary collapse

Class Method Details

.force_config!(configuration) ⇒ Object

Forces a configuration, primarily for testing purposes.



52
53
54
# File 'lib/confinicky/configuration_file.rb', line 52

def self.force_config!(configuration)
  @@configuration = configuration
end

.path_for_key(key: nil) ⇒ Object

Retrieves the value of the environment variables file path.



15
16
17
18
# File 'lib/confinicky/configuration_file.rb', line 15

def self.path_for_key(key: nil)
  self.raise_if_key_not_supported(key)
  self.get_configuration[:files][key]
end

.set_path_for_key(path: "", key: nil) ⇒ Object

Set’s the aliases file path.



22
23
24
25
# File 'lib/confinicky/configuration_file.rb', line 22

def self.set_path_for_key(path: "", key: nil)
  self.raise_if_key_not_supported(key)
  self.get_configuration[:files][key] = path if self.valid_path?(path)
end

.setup?Boolean

Returns true if the configuration file exists along with all specified paths.

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/confinicky/configuration_file.rb', line 44

def self.setup?
  File.exists?(PATH) &&
  File.exists?(self.get_configuration[:files][:env]) &&
  File.exists?(self.get_configuration[:files][:aliases])
end

.tableObject

Returns a terminal table displaying the current configuration.



35
36
37
38
39
# File 'lib/confinicky/configuration_file.rb', line 35

def self.table
  Terminal::Table.new(title: "Configuration", headings: ['type', 'path']) do |t|
    self.get_configuration[:files].each {|k,v| t.add_row [k.to_s,v]}
  end
end

.write!Object

Writes the output to the appropriate YAML file.



29
30
31
# File 'lib/confinicky/configuration_file.rb', line 29

def self.write!
  File.open(PATH, 'w') {|f| f.write self.get_configuration.to_yaml }
end