Class: VCSToolkit::FileStore
- Inherits:
-
Object
- Object
- VCSToolkit::FileStore
- Defined in:
- lib/vcs_toolkit/file_store.rb
Overview
This class is used to implement a custom storage provider for files.
Direct Known Subclasses
Instance Method Summary collapse
- #all_files(path = '', ignore: []) ⇒ Object
-
#changed?(path, blob) ⇒ Boolean
Implement this to compare a file and a blob object.
- #delete(path) ⇒ Object
-
#delete_dir(path) ⇒ Object
Implement this to delete the specified directory.
-
#delete_file(path) ⇒ Object
Implement this to delete the specified file.
- #directories(path = '', ignore: []) ⇒ Object
-
#directory?(path) ⇒ Boolean
Implement this to detect wether a directory with that name exists.
-
#each_directory(path = '') ⇒ Object
Implement this to enumerate over all files.
-
#each_file(path = '') ⇒ Object
Implement this to enumerate over all files in the given directory.
- #exist?(path) ⇒ Boolean
-
#fetch(path) ⇒ Object
Implement this to retrieve a file with the specified name.
-
#file?(path) ⇒ Boolean
Implement this to detect wether a file with that name exists.
- #files(path = '', ignore: []) ⇒ Object
-
#store(path, blob) ⇒ Object
Implement this to store a specific file in persistent storage.
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::*`.
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.
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
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.
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.
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.
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
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.
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.
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.
12 13 14 |
# File 'lib/vcs_toolkit/file_store.rb', line 12 def store(path, blob) raise NotImplementedError, 'You must implement FileStore#store' end |