Class: TFA::Storage

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Storage

Returns a new instance of Storage.



5
6
7
# File 'lib/tfa/storage.rb', line 5

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

Instance Method Details

#allObject



15
16
17
18
19
# File 'lib/tfa/storage.rb', line 15

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

#delete(key) ⇒ Object



33
34
35
36
37
# File 'lib/tfa/storage.rb', line 33

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

#eachObject



9
10
11
12
13
# File 'lib/tfa/storage.rb', line 9

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

#save(key, value) ⇒ Object



27
28
29
30
31
# File 'lib/tfa/storage.rb', line 27

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

#secret_for(key) ⇒ Object



21
22
23
24
25
# File 'lib/tfa/storage.rb', line 21

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