Class: EntityCache::Substitute::EntityCache
Instance Attribute Summary
Attributes inherited from EntityCache
#persist_interval
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add(id, entity, version = nil, time: nil, persisted_version: nil, persisted_time: nil) ⇒ Object
-
#initialize ⇒ EntityCache
constructor
A new instance of EntityCache.
-
#put(id, entity, version, time: nil, persisted_version: nil, persisted_time: nil) ⇒ Object
-
#put?(&blk) ⇒ Boolean
-
#put_records ⇒ Object
Methods inherited from EntityCache
#configure, #entity_class, #get, #persist?, #restore, #specifier
Constructor Details
Returns a new instance of EntityCache.
8
9
|
# File 'lib/entity_cache/substitute.rb', line 8
def initialize
end
|
Class Method Details
.build ⇒ Object
11
12
13
|
# File 'lib/entity_cache/substitute.rb', line 11
def self.build
new
end
|
Instance Method Details
#add(id, entity, version = nil, time: nil, persisted_version: nil, persisted_time: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/entity_cache/substitute.rb', line 15
def add(id, entity, version=nil, time: nil, persisted_version: nil, persisted_time: nil)
version ||= 0
persisted_version ||= version
time ||= clock.now
persisted_time ||= time
record = Record.build(
id,
entity,
version,
time,
persisted_version: persisted_version,
persisted_time: persisted_time
)
internal_store.put(record)
end
|
#put(id, entity, version, time: nil, persisted_version: nil, persisted_time: nil) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/entity_cache/substitute.rb', line 33
def put(id, entity, version, time: nil, persisted_version: nil, persisted_time: nil)
time ||= clock.now
record = Record.build(
id,
entity,
version,
time,
persisted_version: persisted_version,
persisted_time: persisted_time
)
put_records << record
record
end
|
#put?(&blk) ⇒ Boolean
50
51
52
53
54
55
56
|
# File 'lib/entity_cache/substitute.rb', line 50
def put?(&blk)
return put_records.any? if blk.nil?
put_records.any? do |record|
blk.(record)
end
end
|
#put_records ⇒ Object
58
59
60
|
# File 'lib/entity_cache/substitute.rb', line 58
def put_records
@put_records ||= []
end
|