Class: Circuitbox::MemoryStore::Container

Inherits:
Object
  • Object
show all
Includes:
TimeHelper::Monotonic
Defined in:
lib/circuitbox/memory_store/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TimeHelper::Monotonic

current_second

Constructor Details

#initialize(value:, expiry: 0) ⇒ Container

Returns a new instance of Container.



12
13
14
15
# File 'lib/circuitbox/memory_store/container.rb', line 12

def initialize(value:, expiry: 0)
  @value = value
  expires_after(expiry)
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/circuitbox/memory_store/container.rb', line 10

def value
  @value
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/circuitbox/memory_store/container.rb', line 17

def expired?
  @expires_after.positive? && @expires_after < current_second
end

#expired_at?(clock_second) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/circuitbox/memory_store/container.rb', line 21

def expired_at?(clock_second)
  @expires_after.positive? && @expires_after < clock_second
end

#expires_after(seconds = 0) ⇒ Object



25
26
27
# File 'lib/circuitbox/memory_store/container.rb', line 25

def expires_after(seconds = 0)
  @expires_after = seconds.zero? ? seconds : current_second + seconds
end