Class: Rig::Model::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/rig/model/account.rb

Class Method Summary collapse

Class Method Details

.listObject



9
10
11
12
13
14
15
16
# File 'lib/rig/model/account.rb', line 9

def list
  Dir["#{dir}/*"].inject({ }) do |h, e|
    f           = e.gsub("#{dir}/", "")
    f           = File.basename(f, ".yml")
    h[f.to_sym] = e
    h
  end
end

.load(name) ⇒ Object



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

def load(name)
  File.exists?("#{dir}/#{name}.yml") ? YAML::load_file("#{dir}/#{name}.yml") : {}
end

.save(name, data) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rig/model/account.rb', line 18

def save(name, data)
  yaml = data.to_yaml
  file = "#{dir}/#{name}.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