Module: Rig::Config

Defined in:
lib/rig/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dirObject (readonly)

Returns the value of attribute dir.



5
6
7
# File 'lib/rig/config.rb', line 5

def dir
  @dir
end

.loadedObject (readonly)

Returns the value of attribute loaded.



4
5
6
# File 'lib/rig/config.rb', line 4

def loaded
  @loaded
end

Class Method Details

.dataObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rig/config.rb', line 10

def data
  @data ||= begin
    c = File.exists?("#{dir}/config.yml") ? YAML::load_file("#{dir}/config.yml") : {}

    Rig::Log.load(c[:logging])

    Rig::Log.debug "loading plugins from configuration"
    Rig::Plugin.load(c[:plugins]) if c[:plugins]

    c
  end
  @loaded = true
  @data
end

.saveObject



29
30
31
32
33
34
35
36
37
# File 'lib/rig/config.rb', line 29

def save
  yaml = @config.to_yaml
  file = "#@dir/config.yml"
  back = "#{file}.#{Time.now.to_i}"
  Rig::Log.info "backing up configuration -> #{back}"
  FileUtils.cp(file, back)
  File.open(file, "w") { |f| f.write(yaml+"\n") }
  Rig::Log.info "new configuration saved."
end