Class: Storage
- Inherits:
-
Object
- Object
- Storage
- Defined in:
- lib/hubdate/storage.rb
Class Method Summary collapse
- .clear_files(dir) ⇒ Object
- .dir_initialized?(dir) ⇒ Boolean
- .file_initialized?(file) ⇒ Boolean
- .generate_files ⇒ Object
- .generate_follow ⇒ Object
- .generate_star ⇒ Object
- .generate_watch ⇒ Object
- .make_file(dir, file) ⇒ Object
- .make_folder(dir) ⇒ Object
- .write_file(contents, destination) ⇒ Object
Class Method Details
.clear_files(dir) ⇒ Object
8 9 10 |
# File 'lib/hubdate/storage.rb', line 8 def self.clear_files(dir) raise StandardError.new("Unable to delete folder.") unless FileUtils.rm_rf(dir) end |
.dir_initialized?(dir) ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'lib/hubdate/storage.rb', line 26 def self.dir_initialized?(dir) if File.directory?(dir) return true else return false end end |
.file_initialized?(file) ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/hubdate/storage.rb', line 34 def self.file_initialized?(file) if File.exists?(file) return true else return false end end |
.generate_files ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/hubdate/storage.rb', line 54 def self.generate_files Storage.make_folder(File.join(Dir.home, ".hubdate")) self.generate_follow self.generate_star self.generate_watch end |
.generate_follow ⇒ Object
42 43 44 |
# File 'lib/hubdate/storage.rb', line 42 def self.generate_follow Storage.make_file(File.join(Dir.home, ".hubdate") , "followers.yaml") end |
.generate_star ⇒ Object
46 47 48 |
# File 'lib/hubdate/storage.rb', line 46 def self.generate_star Storage.make_file(File.join(Dir.home, ".hubdate"), "stargazers.yaml") end |
.generate_watch ⇒ Object
50 51 52 |
# File 'lib/hubdate/storage.rb', line 50 def self.generate_watch Storage.make_file(File.join(Dir.home, ".hubdate"), "watchers.yaml") end |
.make_file(dir, file) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/hubdate/storage.rb', line 12 def self.make_file(dir, file) f = File.new(File.join(dir, file), "w+") raise StandardError.new("Unable to make file.") unless f f.close end |
.make_folder(dir) ⇒ Object
20 21 22 23 24 |
# File 'lib/hubdate/storage.rb', line 20 def self.make_folder(dir) folder = FileUtils.mkdir(dir) raise StandardError.new("Unable to create directory.") unless folder end |
.write_file(contents, destination) ⇒ Object
2 3 4 5 6 |
# File 'lib/hubdate/storage.rb', line 2 def self.write_file(contents, destination) File.open(destination, "w") do |file| file << contents.to_yaml end end |