Sha256: bcb16494a0f36a6a86ce759d19d9d7fba6d3f8b9695136e04e2b2a84840f3607

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

module TFA
  class Storage
    include Enumerable
    attr_reader :path

    def initialize(path)
      @path = path
      @storage =
        if ".pstore" == File.extname(path)
          PStore.new(path)
        else
          YAML::Store.new(path)
        end
    end

    def each
      all.each do |each|
        yield each
      end
    end

    def all
      open_readonly do |storage|
        storage.roots.map { |key| { key => storage[key] } }
      end
    end

    def secret_for(key)
      open_readonly do |storage|
        storage[key]
      end
    end

    def save(key, value)
      @storage.transaction do
        @storage[key] = value
      end
    end

    def delete(key)
      @storage.transaction do
        @storage.delete(key)
      end
    end

    private

    def open_readonly
      @storage.transaction(true) do
        yield @storage
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tfa-0.0.17 lib/tfa/storage.rb
tfa-0.1.0 lib/tfa/storage.rb
tfa-0.0.16 lib/tfa/storage.rb
tfa-0.0.15 lib/tfa/storage.rb