Class: GvoiceRuby::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/gvoice-ruby/config.rb

Constant Summary collapse

PROJECT_ROOT =
File.expand_path(Pathname.new(__FILE__).ancestor(3))

Class Method Summary collapse

Class Method Details

.load_config(config_file = File.join(PROJECT_ROOT, 'config', 'gvoice-ruby-config.yml')) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gvoice-ruby/config.rb', line 8

def self.load_config(config_file = File.join(PROJECT_ROOT, 'config', 'gvoice-ruby-config.yml'))
  # Load our config
  begin
    if File.exists?(config_file)
      config_hash = File.open(config_file) { |yf| YAML::load(yf) }
    else
      raise IOError
    end
  rescue IOError
    STDERR.puts "Failed to open file #{File.expand_path(config_file)} for reading. File doesn't seem to exist. (#{$!})"
    raise
  end
  return config_hash
end

.write_config(config_hash, config_file = File.join(PROJECT_ROOT, 'config', 'gvoice-ruby-config.yml')) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gvoice-ruby/config.rb', line 23

def self.write_config(config_hash, config_file = File.join(PROJECT_ROOT, 'config', 'gvoice-ruby-config.yml'))
  # Clean things up and put them away
  begin
    if File.exists?(config_file)
      File.open(config_file, 'w' ) do |out_file|
        YAML.dump(config_hash, out_file)
      end
    else
      raise IOError
    end
  rescue IOError
    STDERR.puts "Failed to open #{File.expand_path(config_file)} for writing.  File doesn't seem to exist: (#{$!})"
    raise
  end
end