Class: Syctask::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/syctask/settings.rb

Overview

Creates settings for syctask that are saved to files and retrieved when syctask is started

Instance Method Summary collapse

Instance Method Details

#read_tasksObject

Retrieves the general purpose files from the default_tasks file in the syctask system directory



32
33
34
35
36
37
38
39
# File 'lib/syctask/settings.rb', line 32

def read_tasks
  if File.exists? Syctask::DEFAULT_TASKS and not \
     File.read(Syctask::DEFAULT_TASKS).empty?
    YAML.load_file(Syctask::DEFAULT_TASKS) 
  else
    {}
  end
end

#tasks(tasks) ⇒ Object

Creates general purpose tasks that can be tracked with syctask start. The general purpose files are saved to a file default_tasks in the syctask system directory



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/syctask/settings.rb', line 14

def tasks(tasks)
  service = Syctask::TaskService.new
  if File.exists? Syctask::DEFAULT_TASKS
    general = YAML.load_file(Syctask::DEFAULT_TASKS)
  else
    general = {}
  end
  tasks.split(',').each do |task|
    index = general.keys.find_index(task.upcase)
    general[task.upcase] = service.create(Syctask::SYC_DIR,
                                          {},
                                          task.upcase) unless index
  end
  File.open(Syctask::DEFAULT_TASKS, 'w') {|f| YAML.dump(general, f)}
end