Class: Blertr::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/blertr/options.rb

Class Method Summary collapse

Class Method Details

.config_file_for(name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/blertr/options.rb', line 46

def self.config_file_for name
  if name
    File.join(config_path, "#{name}_config.yaml")
  else
    ""
  end
end

.config_pathObject



37
38
39
40
41
42
43
44
# File 'lib/blertr/options.rb', line 37

def self.config_path
  # first try local config
  path = File.expand_path(CONFIG_DIR_PATH)
  if !File.exists?(path)
    path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config"))
  end
  path
end

.options_for(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blertr/options.rb', line 6

def self.options_for name
  rtn = {}
  if File.exists? config_file_for(name)
    file = File.open(config_file_for(name),'r')
    yaml_data = YAML::load(file)
    file.close
    if yaml_data
      rtn = Hash[yaml_data.map {|k,v| [k.to_sym, v]}]
    end
  end
  rtn
end

.remove_optons_for(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/blertr/options.rb', line 30

def self.remove_optons_for name
  file = config_file_for name
  if File.exists? file
    FileUtils.rm(file)
  end
end

.save_options_for(name, new_options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/blertr/options.rb', line 19

def self.save_options_for name, new_options
  begin
  file = config_file_for name
  File.open(file, 'w') do |file|
    file.puts(YAML::dump(new_options))
  end
  rescue
    puts "problem saving options"
  end
end