Sha256: 5bec4abc1cf05fdbb364a262b3e3a854ce6a48c605471f064cec0f00afda9fc9

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

module TFA
  class Storage
    include Enumerable

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

1 entries across 1 versions & 1 rubygems

Version Path
tfa-0.0.9 lib/tfa/storage.rb