Sha256: 373112b62045aafd7d80675933eba887957c0bdc3c958cbdd3725e42ebe13124

Contents?: true

Size: 593 Bytes

Versions: 3

Compression:

Stored size: 593 Bytes

Contents

require_relative 'monotonic_time'

class Circuitbox
  class MemoryStore
    class Container
      include MonotonicTime

      attr_accessor :value

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

      def expired?
        @expires_after > 0 && @expires_after < current_second
      end

      def expired_at?(clock_second)
        @expires_after > 0 && @expires_after < clock_second
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
circuitbox-2.0.0.pre3 lib/circuitbox/memory_store/container.rb
circuitbox-2.0.0.pre2 lib/circuitbox/memory_store/container.rb
circuitbox-2.0.0.pre1 lib/circuitbox/memory_store/container.rb