Class: EntityCache::Record

Inherits:
Struct
  • Object
show all
Defined in:
lib/entity_cache/record.rb

Defined Under Namespace

Modules: NoStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entity ⇒ Object

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

#id ⇒ Object

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_time ⇒ Object

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_version ⇒ Object

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

#time ⇒ Object

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

#version ⇒ Object

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

Instance Method Details

#age_milliseconds ⇒ Object



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

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

#destructure(includes = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/entity_cache/record.rb', line 10

def destructure(includes=nil)
  return entity if includes.nil?

  responses = [entity]

  includes = Array(includes)

  includes.each do |attribute|
    value = public_send attribute

    if value.nil? && attribute == :version
      value = NoStream.version
    end

    responses << value
  end

  responses
end

#versions_since_persisted ⇒ Object



3
4
5
6
7
8
# File 'lib/entity_cache/record.rb', line 3

def versions_since_persisted
  persisted_version = self.persisted_version
  persisted_version ||= -1

  version - persisted_version.to_i
end