Sha256: 791c21800ca1b0d07557fc25724957b28da6ed653d64ccec5fc02838c5886b17

Contents?: true

Size: 593 Bytes

Versions: 2

Compression:

Stored size: 593 Bytes

Contents

module TFA
  class Storage
    def initialize(filename:)
      @storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
    end

    def all_secrets
      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

    private

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tfa-0.0.8 lib/tfa/storage.rb
tfa-0.0.7 lib/tfa/storage.rb