Class: TomatoHarvest::ListLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/tomatoharvest/list_loader.rb

Constant Summary collapse

FILENAME =
'list.yaml'

Class Method Summary collapse

Class Method Details

.exists_as_file(path) ⇒ Object



29
30
31
# File 'lib/tomatoharvest/list_loader.rb', line 29

def exists_as_file(path)
  File.exists?(path) && !File.directory?(path)
end

.from_fileObject



9
10
11
12
13
14
15
16
17
# File 'lib/tomatoharvest/list_loader.rb', line 9

def from_file
  local_path  = list_path(TomatoHarvest::Config::LOCAL_DIR)

  if File.exists? local_path
    List.init_and_load(local_path)
  else
    load_old_list || List.init_and_load(global_path)
  end
end

.global_pathObject



33
34
35
# File 'lib/tomatoharvest/list_loader.rb', line 33

def global_path
  list_path(TomatoHarvest::Config::GLOBAL_DIR)
end

.list_path(dir) ⇒ Object



37
38
39
# File 'lib/tomatoharvest/list_loader.rb', line 37

def list_path(dir)
  File.join(dir, FILENAME)
end

.load_old_listObject



19
20
21
22
23
24
25
26
27
# File 'lib/tomatoharvest/list_loader.rb', line 19

def load_old_list
  old_path = File.join(TomatoHarvest::Config::HOME_DIR, '.toma')

  if exists_as_file(old_path)
    old_list = List.init_and_load(old_path)
    File.delete old_path
    List.new(global_path, old_list.items).save!
  end
end