Class: TFA::Storage
- Inherits:
-
Object
- Object
- TFA::Storage
- Defined in:
- lib/tfa/storage.rb
Instance Method Summary collapse
- #all_secrets ⇒ Object
-
#initialize(filename) ⇒ Storage
constructor
A new instance of Storage.
- #save(key, value) ⇒ Object
- #secret_for(key) ⇒ Object
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_secrets ⇒ Object
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 |