Module: Mytime::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/mytime/config.rb

Instance Method Summary collapse

Instance Method Details

#add(contents) ⇒ Object

Add yaml data to the existing .mytime config file

Options:

contents: Required hash of data to add to config file


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mytime/config.rb', line 44

def add(contents)
  begin
    data = YAML.load_file USER_FILE
    merged_data = data.merge(contents)
    puts merged_data
    File.open(USER_FILE, 'w') do |file|
      file.write merged_data.to_yaml
    end
  rescue
    puts "Failed adding data. Please try again."
  end
end

#details(path = "") ⇒ Object

Return details of .mytime config file



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

def details(path = "")
  begin
    data = YAML.load_file USER_FILE
    if path == ""
      data
    else
      data.each do |d|
        project = data.select{|key, hash| hash["project_path"] == path }
        return project.first[1] if project.any?
      end
    end
  rescue Exception => e
    {}
  end
end

#save(contents) ⇒ Object

Save a .mytime config file. Overwrites any existing data

Options:

contents: Required hash of  data to save


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

def save(contents)
  begin
    File.open(USER_FILE, 'a') do |file|
      file.write contents.to_yaml
    end
  rescue
    puts "Failed saving information! Please try again."
  end
end