Class: Nanoc::Core::Store Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/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.

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.

API:

  • private

Instance Attribute Summary collapse

Loading and storing data collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

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.

Parameters:

  • The name of the file where data will be loaded from and stored to.

  • The version number corresponding to the file format the data is in. When the file format changes, the version number should be incremented.

API:

  • private



52
53
54
55
# File 'lib/nanoc/core/store.rb', line 52

def initialize(filename, version)
  @filename = filename
  @version  = version
end

Instance Attribute Details

#filenameString (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.

Returns:

  • The name of the file where data will be loaded from and stored to.

API:

  • private



37
38
39
# File 'lib/nanoc/core/store.rb', line 37

def filename
  @filename
end

#versionNumeric (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.

Returns:

  • The version number corresponding to the file format the data is in. When the file format changes, the version number should be incremented.

API:

  • private



42
43
44
# File 'lib/nanoc/core/store.rb', line 42

def version
  @version
end

Class Method Details

.tmp_path_for(store_name:, config:) ⇒ 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.

API:

  • private



22
23
24
25
26
27
# File 'lib/nanoc/core/store.rb', line 22

def self.tmp_path_for(store_name:, config:)
  File.absolute_path(
    File.join(tmp_path_prefix(config.output_dir), store_name),
    config.dir,
  )
end

.tmp_path_prefix(output_dir) ⇒ 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.

API:

  • private



30
31
32
33
# File 'lib/nanoc/core/store.rb', line 30

def self.tmp_path_prefix(output_dir)
  dir = Digest::SHA1.hexdigest(output_dir)[0..12]
  File.join('tmp', 'nanoc', dir)
end

Instance Method Details

#dataObject

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 is abstract.

This method must be implemented by the subclass.

Returns The data that should be written to the disk.

Returns:

  • The data that should be written to the disk

Raises:

API:

  • private



62
63
64
65
66
# File 'lib/nanoc/core/store.rb', line 62

def data
  raise NotImplementedError.new(
    'Nanoc::Core::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 is abstract.

This method must be implemented by the subclass.

This method returns an undefined value.

Parameters:

  • The data that has been loaded from the disk

Raises:

API:

  • private



73
74
75
76
77
# File 'lib/nanoc/core/store.rb', line 73

def data=(new_data) # rubocop:disable Lint/UnusedMethodArgument
  raise NotImplementedError.new(
    'Nanoc::Core::Store subclasses must implement #data and #data=',
  )
end

#loadvoid

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.

API:

  • private



83
84
85
86
87
# File 'lib/nanoc/core/store.rb', line 83

def load
  Nanoc::Core::Instrumentor.call(:store_loaded, self.class) do
    load_uninstrumented
  end
end

#storevoid

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.

API:

  • private



93
94
95
96
97
98
99
# File 'lib/nanoc/core/store.rb', line 93

def store
  # NOTE: Yes, the “store stored” name is a little silly. Maybe stores
  # need to be renamed to databases or so.
  Nanoc::Core::Instrumentor.call(:store_stored, self.class) do
    store_uninstrumented
  end
end