Class: ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dinner/configmanager.rb

Overview

This class is for creating/accessing a config file with options for Dinner

Constant Summary collapse

DEFAULT =

The defaults for the config file

{
  :build_folder => "build",
  :copy_formats => ["js","css"]
}
@@config =
{}

Class Method Summary collapse

Class Method Details

.configObject

Access the configuration hash



13
14
15
# File 'lib/dinner/configmanager.rb', line 13

def self.config
  @@config
end

.defaultObject

A getter method for the config defaults



18
19
20
# File 'lib/dinner/configmanager.rb', line 18

def self.default
  DEFAULT
end

.init_configObject

Create a config file if there isn’t yet one



23
24
25
26
27
28
29
30
31
32
# File 'lib/dinner/configmanager.rb', line 23

def self.init_config
  if File.exists?("#{Dir.pwd}/dinconfig.yaml")
    self.load_config("#{Dir.pwd}/dinconfig.yaml")
  else
    File.open("#{Dir.pwd}/dinconfig.yaml","w+") do |file|
      file.puts(DEFAULT.to_yaml)
    end
    self.load_config("#{Dir.pwd}/dinconfig.yaml")
  end
end

.load_config(file_path) ⇒ Object

Load the current config file



35
36
37
# File 'lib/dinner/configmanager.rb', line 35

def self.load_config(file_path)
  @@config = YAML.load(File.read(file_path))
end