Class: Nanoc::Core::ChecksumStore Private

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

Stores checksums for objects in order to be able to detect whether a file has changed since the last site compilation.

Instance Attribute Summary collapse

Attributes inherited from Store

#filename, #version

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Methods inherited from Store

#load, #store, tmp_path_for, tmp_path_prefix

Constructor Details

#initialize(config:, objects:) ⇒ ChecksumStore

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 a new instance of ChecksumStore.



18
19
20
21
22
23
24
# File 'lib/nanoc/core/checksum_store.rb', line 18

def initialize(config:, objects:)
  super(Nanoc::Core::Store.tmp_path_for(config: config, store_name: 'checksums'), 2)

  @objects = objects

  @checksums = {}
end

Instance Attribute Details

#checksums=(value) ⇒ Object (writeonly)

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.



12
13
14
# File 'lib/nanoc/core/checksum_store.rb', line 12

def checksums=(value)
  @checksums = value
end

#objectsObject

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.



13
14
15
# File 'lib/nanoc/core/checksum_store.rb', line 13

def objects
  @objects
end

Instance Method Details

#[](obj) ⇒ 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.



27
28
29
# File 'lib/nanoc/core/checksum_store.rb', line 27

def [](obj)
  @checksums[obj.reference]
end

#add(obj) ⇒ 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.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nanoc/core/checksum_store.rb', line 32

def add(obj)
  if obj.is_a?(Nanoc::Core::Document)
    @checksums[[obj.reference, :content]] = Nanoc::Core::Checksummer.calc_for_content_of(obj)
  end

  if obj.is_a?(Nanoc::Core::Document) || obj.is_a?(Nanoc::Core::Configuration)
    @checksums[[obj.reference, :each_attribute]] = Nanoc::Core::Checksummer.calc_for_each_attribute_of(obj)
  end

  @checksums[obj.reference] = Nanoc::Core::Checksummer.calc(obj)

  self
end

#attributes_checksum_for(obj) ⇒ 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.



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

def attributes_checksum_for(obj)
  @checksums[[obj.reference, :each_attribute]]
end

#content_checksum_for(obj) ⇒ 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.



47
48
49
# File 'lib/nanoc/core/checksum_store.rb', line 47

def content_checksum_for(obj)
  @checksums[[obj.reference, :content]]
end