Class: ActiveSanction::ValidatorStore
- Inherits:
-
Object
- Object
- ActiveSanction::ValidatorStore
show all
- Extended by:
- T::Sig
- Defined in:
- lib/active_sanction/validator_store.rb,
lib/active_sanction/validator_store/memory.rb,
lib/active_sanction/validator_store/file_system.rb
Overview
Where a process remembers what a publisher last said about a list, so the
next fetch can ask "still this?" instead of "give me everything".
store = ActiveSanction::ValidatorStore::FileSystem.new
store[:ofac_sdn] store.delete(:ofac_sdn)
Keys are the caller's: a URL by default, or a stable source name for an
adapter (#12) whose publisher may move its file. Validators carry the URL
they came from either way, so a moved file is detected rather than sent a
meaningless If-None-Match.
This is a base class rather than an interface document: subclasses supply
the two lines that differ -- how the entries are read and how a change to
them is committed -- and inherit the rest. #24 will do the same for
snapshots, at a scale where the difference matters more.
Defined Under Namespace
Classes: CorruptStore, FileSystem, Memory
Instance Method Summary
collapse
Instance Method Details
Reads validators, or nil when nothing is stored under the key. Nil is the
answer to "have we ever fetched this?", so it is not conflated with a
record that exists but carries no validators.
39
40
41
|
# File 'lib/active_sanction/validator_store.rb', line 39
def [](key)
entries[key!(key)]
end
|
#[]=(key, validators) ⇒ Validators?
Also known as:
store
Storing nil, or validators the publisher gave nothing to be conditional
with, is a delete: a record that cannot save a download is not worth
keeping, and leaving one behind makes #stale? lie about having a usable
copy.
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/active_sanction/validator_store.rb', line 48
def []=(key, validators)
normalized = key!(key)
commit do |all|
if validators.nil? || validators.empty?
all.delete(normalized)
else
all[normalized] = validators
end
end
validators
end
|
#clear ⇒ T.self_type
80
81
82
83
|
# File 'lib/active_sanction/validator_store.rb', line 80
def clear
commit(&:clear)
self
end
|
#delete(key) ⇒ T.untyped
62
63
64
65
|
# File 'lib/active_sanction/validator_store.rb', line 62
def delete(key)
normalized = key!(key)
commit { |all| all.delete(normalized) }
end
|
#empty? ⇒ Boolean
77
|
# File 'lib/active_sanction/validator_store.rb', line 77
def empty? = entries.empty?
|
#inspect ⇒ String
89
|
# File 'lib/active_sanction/validator_store.rb', line 89
def inspect = "#<#{self.class} #{size} entr#{size == 1 ? "y" : "ies"}>"
|
#key?(key) ⇒ Boolean
68
|
# File 'lib/active_sanction/validator_store.rb', line 68
def key?(key) = entries.key?(key!(key))
|
#keys ⇒ Array<String>
71
|
# File 'lib/active_sanction/validator_store.rb', line 71
def keys = entries.keys
|
#size ⇒ Integer
74
|
# File 'lib/active_sanction/validator_store.rb', line 74
def size = entries.size
|
#to_h ⇒ Hash{String => T.untyped}
86
|
# File 'lib/active_sanction/validator_store.rb', line 86
def to_h = entries.transform_values(&:to_h)
|