Class: Picky::Backends::File::Basic
- Includes:
- Helpers::File
- Defined in:
- lib/picky/backends/file/basic.rb
Overview
Base class for all file-based index files.
Provides necessary helper methods for its subclasses. Not directly useable, as it does not provide dump/load methods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
This index file’s location.
-
#mapping_file ⇒ Object
readonly
This index file’s location.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the file.
-
#empty ⇒ Object
The empty index that is used for putting the index together before it is saved into the files.
-
#extension ⇒ Object
The default extension for index files is “index”.
-
#initial ⇒ Object
The initial content before loading.
-
#initialize(cache_path, options = {}) ⇒ Basic
constructor
An index cache takes a path, without file extension, which will be provided by the subclasses.
- #to_s ⇒ Object
Constructor Details
#initialize(cache_path, options = {}) ⇒ Basic
An index cache takes a path, without file extension, which will be provided by the subclasses.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/picky/backends/file/basic.rb', line 24 def initialize cache_path, = {} @cache_path = "#{cache_path}.file.#{extension}" # This is the mapping file with the in-memory hash for the # file position/offset mappings. # @mapping_file = Memory::JSON.new "#{cache_path}.file_mapping" @empty = [:empty] @initial = [:initial] end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
This index file’s location.
18 19 20 |
# File 'lib/picky/backends/file/basic.rb', line 18 def cache_path @cache_path end |
#mapping_file ⇒ Object (readonly)
This index file’s location.
18 19 20 |
# File 'lib/picky/backends/file/basic.rb', line 18 def mapping_file @mapping_file end |
Instance Method Details
#delete ⇒ Object
Deletes the file.
60 61 62 63 64 |
# File 'lib/picky/backends/file/basic.rb', line 60 def delete mapping_file.delete `rm -Rf #{cache_path}` end |
#empty ⇒ Object
The empty index that is used for putting the index together before it is saved into the files.
45 46 47 |
# File 'lib/picky/backends/file/basic.rb', line 45 def empty @empty && @empty.clone || {} end |
#extension ⇒ Object
The default extension for index files is “index”.
38 39 40 |
# File 'lib/picky/backends/file/basic.rb', line 38 def extension :index end |
#initial ⇒ Object
The initial content before loading.
Note: We could also load the mapping file
as in #load.
54 55 56 |
# File 'lib/picky/backends/file/basic.rb', line 54 def initial @initial && @initial.clone || {} end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/picky/backends/file/basic.rb', line 68 def to_s "#{self.class}(#{cache_path},#{mapping_file.cache_path})" end |