Module: Ptf::Config

Defined in:
lib/ptf/config.rb

Constant Summary collapse

YAML_LOCATION =
File.join(Dir.home, ".ptfconfig")
EDITABLE =
{
  :default_group => "unassigned:NONE",
  :base_dir => File.join(Dir.home, ".ptf")
}
STATIC =
{
  :file_permission => 0700,
  :id_counter_start => "1",
  :task_metadata_dir => "info",
  :task_data_dir => "data",
  :in_progress_dir => "open",
  :completed_dir => "closed",
  :tmp_dir => "tmp",
  :task_counter_file => "id_counter",
  :group_list_file => "group_list"
}

Class Method Summary collapse

Class Method Details

.get_configObject



24
25
26
27
28
29
30
# File 'lib/ptf/config.rb', line 24

def self.get_config
  yaml_settings = {}

  yaml_settings = YAML.load(File.read(YAML_LOCATION)) if File.exist?(YAML_LOCATION)

  EDITABLE.merge(yaml_settings).merge(STATIC)
end

.write_config(config) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ptf/config.rb', line 32

def self.write_config(config)
  new_config = EDITABLE.merge config.select { |k| EDITABLE.keys.include? k }

  yaml_file = File.new(YAML_LOCATION, "w")
  yaml_file.puts new_config.to_yaml
  yaml_file.close
end