/
checksum_store.rb
45 lines (38 loc) · 1.1 KB
/
checksum_store.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Nanoc::Int
# Stores checksums for objects in order to be able to detect whether a file
# has changed since the last site compilation.
#
# @api private
class ChecksumStore < ::Nanoc::Int::Store
# @param [Nanoc::Int::Site] site
def initialize(site: nil)
super(Nanoc::Int::Store.tmp_path_for(env: (site.config.env if site), store_name: 'checksums'), 1)
@site = site
@checksums = {}
end
# Returns the old checksum for the given object. This makes sense for
# items, layouts and code snippets.
#
# @param [#reference] obj The object for which to fetch the checksum
#
# @return [String] The checksum for the given object
def [](obj)
@checksums[obj.reference]
end
# Sets the checksum for the given object.
#
# @param [#reference] obj The object for which to set the checksum
#
# @param [String] checksum The checksum
def []=(obj, checksum)
@checksums[obj.reference] = checksum
end
protected
def data
@checksums
end
def data=(new_data)
@checksums = new_data
end
end
end