Class: TomatoHarvest::ListLoader
- Inherits:
-
Object
- Object
- TomatoHarvest::ListLoader
- Defined in:
- lib/tomatoharvest/list_loader.rb
Constant Summary collapse
- FILENAME =
'list.yaml'
Class Method Summary collapse
- .exists_as_file(path) ⇒ Object
- .from_file ⇒ Object
- .global_path ⇒ Object
- .list_path(dir) ⇒ Object
- .load_old_list ⇒ Object
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_file ⇒ Object
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_path ⇒ Object
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_list ⇒ Object
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 |