Sha256: 8f61c8c790f606145ab571bb9c923bffd46536eef58f94d5895fda107c2bac03

Contents?: true

Size: 693 Bytes

Versions: 2

Compression:

Stored size: 693 Bytes

Contents

module TFA
  class Storage
    include Enumerable

    def initialize(options)
      @storage = PStore.new(File.join(Dir.home, ".#{options[:filename]}.pstore"))
    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

    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.11 lib/tfa/storage.rb
tfa-0.0.10 lib/tfa/storage.rb