Class: Nanoc::Int::Store Abstract Private
- Inherits:
-
Object
- Object
- Nanoc::Int::Store
- Defined in:
- lib/nanoc/base/repos/store.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Subclasses must implement #data and #data=, and may implement #no_data_found and #version_mismatch_detected.
An abstract superclass for classes that need to store data to the filesystem, such as checksums, cached compiled content and dependency graphs.
Each store has a version number. When attempting to load data from a store that has an incompatible version number, no data will be loaded, but #version_mismatch_detected will be called.
Direct Known Subclasses
ChecksumStore, CompiledContentCache, DependencyStore, RuleMemoryStore
Instance Attribute Summary collapse
-
#filename ⇒ String
readonly
private
The name of the file where data will be loaded from and stored to.
-
#version ⇒ Numeric
readonly
private
The version number corresponding to the file format the data is in.
Loading and storing data collapse
-
#data ⇒ Object
abstract
private
The data that should be written to the disk.
- #data=(new_data) ⇒ void abstract private
-
#load ⇒ void
private
Loads the data from the filesystem into memory.
-
#store ⇒ void
private
Stores the data contained in memory to the filesystem.
Callback methods collapse
-
#no_data_found ⇒ void
private
Callback method that is called when no data file was found.
-
#version_mismatch_detected ⇒ void
private
Callback method that is called when a version mismatch is detected.
Instance Method Summary collapse
-
#initialize(filename, version) ⇒ Store
constructor
private
Creates a new store for the given filename.
Constructor Details
#initialize(filename, version) ⇒ Store
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new store for the given filename.
32 33 34 35 |
# File 'lib/nanoc/base/repos/store.rb', line 32 def initialize(filename, version) @filename = filename @version = version end |
Instance Attribute Details
#filename ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The name of the file where data will be loaded from and stored to.
17 18 19 |
# File 'lib/nanoc/base/repos/store.rb', line 17 def filename @filename end |
#version ⇒ Numeric (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The version number corresponding to the file format the data is in. When the file format changes, the version number should be incremented.
22 23 24 |
# File 'lib/nanoc/base/repos/store.rb', line 22 def version @version end |
Instance Method Details
#data ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method must be implemented by the subclass.
Returns The data that should be written to the disk.
42 43 44 |
# File 'lib/nanoc/base/repos/store.rb', line 42 def data raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=') end |
#data=(new_data) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method must be implemented by the subclass.
This method returns an undefined value.
51 52 53 |
# File 'lib/nanoc/base/repos/store.rb', line 51 def data=(new_data) # rubocop:disable Lint/UnusedMethodArgument raise NotImplementedError.new('Nanoc::Int::Store subclasses must implement #data and #data=') end |
#load ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Loads the data from the filesystem into memory. This method will set the
loaded data using the {#data=} method.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nanoc/base/repos/store.rb', line 59 def load # Check file existance unless File.file?(filename) no_data_found return end begin pstore.transaction do # Check version if pstore[:version] != version version_mismatch_detected return end # Load self.data = pstore[:data] end rescue FileUtils.rm_f(filename) load end end |
#no_data_found ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Callback method that is called when no data file was found. By default, this implementation does nothing, but it should probably be overridden by the subclass.
103 104 |
# File 'lib/nanoc/base/repos/store.rb', line 103 def no_data_found end |
#store ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Stores the data contained in memory to the filesystem. This method will
use the {#data} method to fetch the data that should be written.
87 88 89 90 91 92 93 94 |
# File 'lib/nanoc/base/repos/store.rb', line 87 def store FileUtils.mkdir_p(File.dirname(filename)) pstore.transaction do pstore[:data] = data pstore[:version] = version end end |
#version_mismatch_detected ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Callback method that is called when a version mismatch is detected. By default, this implementation does nothing, but it should probably be overridden by the subclass.
111 112 |
# File 'lib/nanoc/base/repos/store.rb', line 111 def version_mismatch_detected end |