Class: EntityCache::Record

Inherits:
Struct
  • Object
show all
Includes:
Dependency
Defined in:
lib/entity_cache/record.rb,
lib/entity_cache/record.rb,
lib/entity_cache/record/log_text.rb,
lib/entity_cache/record/destructure.rb,
lib/entity_cache/record/transformer.rb

Defined Under Namespace

Modules: Destructure, LogText, Transformer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entityObject

Returns the value of attribute entity

Returns:

  • (Object)

    the current value of entity



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def entity
  @entity
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def id
  @id
end

#persisted_timeObject

Returns the value of attribute persisted_time

Returns:

  • (Object)

    the current value of persisted_time



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def persisted_time
  @persisted_time
end

#persisted_versionObject

Returns the value of attribute persisted_version

Returns:

  • (Object)

    the current value of persisted_version



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def persisted_version
  @persisted_version
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def time
  @time
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



2
3
4
# File 'lib/entity_cache/record.rb', line 2

def version
  @version
end

Class Method Details

.build(id, entity, version, time, persisted_version: nil, persisted_time: nil) ⇒ Object



20
21
22
23
24
# File 'lib/entity_cache/record.rb', line 20

def self.build(id, entity, version, time, persisted_version: nil, persisted_time: nil)
  instance = new(id, entity, version, time, persisted_version, persisted_time)
  instance.configure
  instance
end

.destructure(instance, includes = nil) ⇒ Object



26
27
28
# File 'lib/entity_cache/record.rb', line 26

def self.destructure(instance, includes=nil)
  Destructure.(instance, includes)
end

Instance Method Details

#age_millisecondsObject



30
31
32
# File 'lib/entity_cache/record.rb', line 30

def age_milliseconds
  Clock::UTC.elapsed_milliseconds(time, clock.now)
end

#configureObject



16
17
18
# File 'lib/entity_cache/record.rb', line 16

def configure
  Clock::UTC.configure(self)
end

#persisted_age_millisecondsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/entity_cache/record.rb', line 34

def persisted_age_milliseconds
  if persisted_time.nil?
    nil
  else
    Clock::UTC.elapsed_milliseconds(
      persisted_time,
      time
    )
  end
end

#persisted_age_versionsObject



45
46
47
48
49
50
51
# File 'lib/entity_cache/record.rb', line 45

def persisted_age_versions
  if persisted_version.nil?
    nil
  else
    version - persisted_version
  end
end