Class: EntityCache::Store::External::Substitute::External

Inherits:
Object
  • Object
show all
Includes:
EntityCache::Store::External
Defined in:
lib/entity_cache/store/external/substitute.rb

Constant Summary

Constants included from EntityCache::Store::External

Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EntityCache::Store::External

#entity_class, included, #specifier

Instance Attribute Details

#telemetry_sinkObject

Returns the value of attribute telemetry_sink.



12
13
14
# File 'lib/entity_cache/store/external/substitute.rb', line 12

def telemetry_sink
  @telemetry_sink
end

Class Method Details

.buildObject



14
15
16
17
18
# File 'lib/entity_cache/store/external/substitute.rb', line 14

def self.build
  instance = new(subject)
  instance.configure
  instance
end

.subjectObject



57
58
59
# File 'lib/entity_cache/store/external/substitute.rb', line 57

def self.subject
  :substitute
end

Instance Method Details

#add(id, entity, version, time) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/entity_cache/store/external/substitute.rb', line 36

def add(id, entity, version, time)
  record = Record.new(id, entity, version, time)

  get_records[id] = record

  record
end

#configure(session: nil) ⇒ Object



20
21
22
# File 'lib/entity_cache/store/external/substitute.rb', line 20

def configure(session: nil)
  self.telemetry_sink = self.class.register_telemetry_sink(self)
end

#get(id) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/entity_cache/store/external/substitute.rb', line 24

def get(id)
  record = get_records[id]

  if record
    return record.entity, record.version, record.time
  end
end

#get_recordsObject



32
33
34
# File 'lib/entity_cache/store/external/substitute.rb', line 32

def get_records
  @get_records ||= {}
end

#putObject



44
45
# File 'lib/entity_cache/store/external/substitute.rb', line 44

def put(*)
end

#put?(&block) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
# File 'lib/entity_cache/store/external/substitute.rb', line 47

def put?(&block)
  block ||= proc { true }

  telemetry_sink.recorded_put? do |record|
    data = record.data

    block.(data.id, data.entity, data.version, data.time)
  end
end