Class: Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/hubdate/storage.rb

Class Method Summary collapse

Class Method Details

.clear_files(dir) ⇒ Object

Raises:

  • (StandardError)


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

Returns:

  • (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

Returns:

  • (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_filesObject



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_followObject



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_starObject



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_watchObject



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

Raises:

  • (StandardError)


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

Raises:

  • (StandardError)


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