Class: TFA::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/tfa/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Storage

Returns a new instance of Storage.



3
4
5
# File 'lib/tfa/storage.rb', line 3

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

Instance Method Details

#all_secretsObject



7
8
9
10
11
# File 'lib/tfa/storage.rb', line 7

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

#save(key, value) ⇒ Object



19
20
21
22
23
# File 'lib/tfa/storage.rb', line 19

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

#secret_for(key) ⇒ Object



13
14
15
16
17
# File 'lib/tfa/storage.rb', line 13

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