Class: VCSToolkit::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/vcs_toolkit/file_store.rb

Overview

This class is used to implement a custom storage provider for files.

Direct Known Subclasses

Utils::MemoryFileStore

Instance Method Summary collapse

Instance Method Details

#all_files(path = '', ignore: []) ⇒ Object



93
94
95
# File 'lib/vcs_toolkit/file_store.rb', line 93

def all_files(path='', ignore: [])
  enum_for :yield_all_files, path, ignore: ignore
end

#changed?(path, blob) ⇒ Boolean

Implement this to compare a file and a blob object. It should return boolean value to indicate wether the file is different.

The hash algorithm should be the same one used in ‘Objects::*`.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/vcs_toolkit/file_store.rb', line 59

def changed?(path, blob)
  raise NotImplementedError, 'You must implement FileStore#changed?'
end

#delete(path) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vcs_toolkit/file_store.rb', line 97

def delete(path)
  if directory? path
    files(path).each do |file|
      delete_file File.join(path, file)
    end

    directories(path).each do |directory|
      delete File.join(path, directory)
    end

    delete_dir path
  else
    delete_file path
  end
end

#delete_dir(path) ⇒ Object

Implement this to delete the specified directory. This method will be called only on empty directories. Use #delete if you want to recursively delete a directory.

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/vcs_toolkit/file_store.rb', line 35

def delete_dir(path)
  raise NotImplementedError, 'You must implement FileStore#delete_dir'
end

#delete_file(path) ⇒ Object

Implement this to delete the specified file

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/vcs_toolkit/file_store.rb', line 26

def delete_file(path)
  raise NotImplementedError, 'You must implement FileStore#delete_file'
end

#directories(path = '', ignore: []) ⇒ Object



89
90
91
# File 'lib/vcs_toolkit/file_store.rb', line 89

def directories(path='', ignore: [])
  enum_for(:each_directory, path).reject { |file| ignored? file, ignore }
end

#directory?(path) ⇒ Boolean

Implement this to detect wether a directory with that name exists.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/vcs_toolkit/file_store.rb', line 49

def directory?(path)
  raise NotImplementedError, 'You must implement FileStore#directory?'
end

#each_directory(path = '') ⇒ Object

Implement this to enumerate over all files.

The order of enumeration doesn’t matter.

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/vcs_toolkit/file_store.rb', line 77

def each_directory(path='')
  raise NotImplementedError, 'You must implement FileStore#each_directory'
end

#each_file(path = '') ⇒ Object

Implement this to enumerate over all files in the given directory.

The order of enumeration doesn’t matter.

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/vcs_toolkit/file_store.rb', line 68

def each_file(path='')
  raise NotImplementedError, 'You must implement FileStore#each_file'
end

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/vcs_toolkit/file_store.rb', line 81

def exist?(path)
  file?(path) or directory?(path)
end

#fetch(path) ⇒ Object

Implement this to retrieve a file with the specified name.

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/vcs_toolkit/file_store.rb', line 19

def fetch(path)
  raise NotImplementedError, 'You must implement FileStore#fetch'
end

#file?(path) ⇒ Boolean

Implement this to detect wether a file with that name exists.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/vcs_toolkit/file_store.rb', line 42

def file?(path)
  raise NotImplementedError, 'You must implement FileStore#file?'
end

#files(path = '', ignore: []) ⇒ Object



85
86
87
# File 'lib/vcs_toolkit/file_store.rb', line 85

def files(path='', ignore: [])
  enum_for(:each_file, path).reject { |file| ignored? file, ignore }
end

#store(path, blob) ⇒ Object

Implement this to store a specific file in persistent storage.

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/vcs_toolkit/file_store.rb', line 12

def store(path, blob)
  raise NotImplementedError, 'You must implement FileStore#store'
end