Class: Circuitbox::MemoryStore::Container
- Inherits:
-
Object
- Object
- Circuitbox::MemoryStore::Container
- Includes:
- TimeHelper::Monotonic
- Defined in:
- lib/circuitbox/memory_store/container.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #expired_at?(clock_second) ⇒ Boolean
- #expires_after(seconds = 0) ⇒ Object
-
#initialize(value:, expiry: 0) ⇒ Container
constructor
A new instance of Container.
Methods included from TimeHelper::Monotonic
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
#value ⇒ Object
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
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
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 |