Class: EntityCache::Store::Internal

Inherits:
Object
  • Object
show all
Includes:
Log::Dependency, Virtual
Defined in:
lib/entity_cache/store/internal.rb,
lib/entity_cache/store/internal/build.rb,
lib/entity_cache/store/internal/substitute.rb,
lib/entity_cache/store/internal/scope/global.rb,
lib/entity_cache/store/internal/scope/thread.rb,
lib/entity_cache/store/internal/build/defaults.rb,
lib/entity_cache/store/internal/scope/exclusive.rb

Defined Under Namespace

Modules: Build, Scope, Substitute

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



7
8
9
# File 'lib/entity_cache/store/internal.rb', line 7

def subject
  @subject
end

Class Method Details

.build(subject) ⇒ Object



9
10
11
12
13
# File 'lib/entity_cache/store/internal.rb', line 9

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

.configure(receiver, subject, scope: nil, attr_name: nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/entity_cache/store/internal.rb', line 15

def self.configure(receiver, subject, scope: nil, attr_name: nil)
  attr_name ||= :internal_store

  instance = Build.(subject, scope: scope)
  receiver.public_send("#{attr_name}=", instance)
  instance
end

Instance Method Details

#countObject Also known as: length



51
52
53
# File 'lib/entity_cache/store/internal.rb', line 51

def count
  records.count
end

#delete(id) ⇒ Object



47
48
49
# File 'lib/entity_cache/store/internal.rb', line 47

def delete(id)
  records.delete(id)
end

#empty?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/entity_cache/store/internal.rb', line 56

def empty?
  records.empty?
end

#get(id) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/entity_cache/store/internal.rb', line 25

def get(id)
  logger.trace { "Getting Entity (ID: #{id.inspect})" }

  record = records[id]

  logger.debug { "Get entity done (ID: #{id.inspect}, #{Record::LogText.get(record)})" }

  record
end

#put(record) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/entity_cache/store/internal.rb', line 35

def put(record)
  id = record.id

  logger.trace { "Putting entity (ID: #{id.inspect}, #{Record::LogText.get(record)})" }

  records[id] = record

  logger.trace { "Put entity done (ID: #{id.inspect}, #{Record::LogText.get(record)})" }

  record
end