Class: Picky::Backends::Memory::Basic
- Includes:
- Helpers::File
- Defined in:
- lib/picky/backends/memory/basic.rb
Overview
Base class for all memory-based index files.
Provides necessary helper methods for its subclasses. Not directly useable, as it does not provide dump/load methods.
Instance Attribute Summary collapse
-
#cache_file_path ⇒ Object
readonly
This file’s cache file without extensions.
-
#hash_type ⇒ Object
readonly
What hash type to use.
Instance Method Summary collapse
- #cache_path ⇒ Object
-
#delete ⇒ Object
Deletes the file.
-
#empty ⇒ Object
The empty index that is used for putting the index together before it is dumped into the files.
-
#extension ⇒ Object
The default extension for index files is “index”.
-
#initial ⇒ Object
The initial content before loading from file/indexing.
-
#initialize(cache_file_path, hash_type = Hash, options = {}) ⇒ Basic
constructor
An index cache takes a path, without file extension, which will be provided by the subclasses.
- #to_s ⇒ Object
- #type ⇒ Object
Methods included from Helpers::File
Constructor Details
#initialize(cache_file_path, hash_type = Hash, options = {}) ⇒ Basic
An index cache takes a path, without file extension, which will be provided by the subclasses.
29 30 31 32 33 34 |
# File 'lib/picky/backends/memory/basic.rb', line 29 def initialize cache_file_path, hash_type = Hash, = {} @cache_file_path = cache_file_path @hash_type = hash_type @empty = [:empty] @initial = [:initial] end |
Instance Attribute Details
#cache_file_path ⇒ Object (readonly)
This file’s cache file without extensions.
20 21 22 |
# File 'lib/picky/backends/memory/basic.rb', line 20 def cache_file_path @cache_file_path end |
#hash_type ⇒ Object (readonly)
What hash type to use. Default: ::Hash
24 25 26 |
# File 'lib/picky/backends/memory/basic.rb', line 24 def hash_type @hash_type end |
Instance Method Details
#cache_path ⇒ Object
44 45 46 |
# File 'lib/picky/backends/memory/basic.rb', line 44 def cache_path [cache_file_path, type, extension].join(?.) end |
#delete ⇒ Object
Deletes the file.
63 64 65 |
# File 'lib/picky/backends/memory/basic.rb', line 63 def delete `rm -Rf #{cache_path}` end |
#empty ⇒ Object
The empty index that is used for putting the index together before it is dumped into the files.
51 52 53 |
# File 'lib/picky/backends/memory/basic.rb', line 51 def empty @empty && @empty.clone || hash_type.new end |
#extension ⇒ Object
The default extension for index files is “index”.
38 39 40 |
# File 'lib/picky/backends/memory/basic.rb', line 38 def extension :index end |
#initial ⇒ Object
The initial content before loading from file/indexing.
57 58 59 |
# File 'lib/picky/backends/memory/basic.rb', line 57 def initial @initial && @initial.clone || hash_type.new end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/picky/backends/memory/basic.rb', line 69 def to_s "#{self.class}(#{cache_path})" end |
#type ⇒ Object
41 42 43 |
# File 'lib/picky/backends/memory/basic.rb', line 41 def type :memory end |