Sha256: ea5f855d99bd4472b7e2a63b3cb025cb7b7d834eb68c524d3d70c5dc59bd9231

Contents?: true

Size: 732 Bytes

Versions: 6

Compression:

Stored size: 732 Bytes

Contents

require 'certmeister/store_error'

module Certmeister

  class InMemoryStore

    include Enumerable

    def initialize(certs = {})
      @certs = certs
      @healthy = true
    end

    def store(cn, cert)
      fail_if_unhealthy
      @certs[cn] = cert
    end

    def fetch(cn)
      fail_if_unhealthy
      @certs[cn]
    end

    def remove(cn)
      fail_if_unhealthy
      !!@certs.delete(cn)
    end

    def each
      @certs.each do |cn, cert|
        yield cn, cert
      end
    end

    def health_check
      @healthy
    end

    private

    def break!
      @healthy = false
    end

    def fail_if_unhealthy
      raise Certmeister::StoreError.new("in-memory store is broken") if !@healthy
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
certmeister-2.3.2 lib/certmeister/in_memory_store.rb
certmeister-2.3.1 lib/certmeister/in_memory_store.rb
certmeister-2.3.0 lib/certmeister/in_memory_store.rb
certmeister-2.2.0 lib/certmeister/in_memory_store.rb
certmeister-2.1.0 lib/certmeister/in_memory_store.rb
certmeister-2.0.0 lib/certmeister/in_memory_store.rb