/
outdatedness_store.rb
49 lines (39 loc) · 1.11 KB
/
outdatedness_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
46
47
48
49
module Nanoc::Int
# @api private
class OutdatednessStore < ::Nanoc::Int::Store
include Nanoc::Int::ContractsSupport
contract C::KeywordArgs[site: C::Maybe[Nanoc::Int::Site], reps: Nanoc::Int::ItemRepRepo] => C::Any
def initialize(site: nil, reps:) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/outdatedness', 1)
@outdated_reps = Set.new
@all_reps = reps
end
contract Nanoc::Int::ItemRep => C::Bool
def include?(obj)
@outdated_reps.include?(obj)
end
contract Nanoc::Int::ItemRep => self
def add(obj)
@outdated_reps << obj
self
end
contract Nanoc::Int::ItemRep => self
def remove(obj)
@outdated_reps.delete(obj)
self
end
contract C::None => C::ArrayOf[Nanoc::Int::ItemRep]
def to_a
@outdated_reps.to_a
end
protected
def data
@outdated_reps.map(&:reference)
end
def data=(new_data)
outdated_refs = Set.new(new_data)
all_reps = Set.new(@all_reps)
@outdated_reps = Set.new(all_reps.select { |rep| outdated_refs.include?(rep.reference) })
end
end
end