Class: TFA::Storage
Instance Method Summary collapse
- #all ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
-
#initialize(options) ⇒ Storage
constructor
A new instance of Storage.
- #save(key, value) ⇒ Object
- #secret_for(key) ⇒ Object
Constructor Details
#initialize(options) ⇒ Storage
Returns a new instance of Storage.
5 6 7 |
# File 'lib/tfa/storage.rb', line 5 def initialize() @storage = PStore.new(File.join(Dir.home, ".#{[:filename]}.pstore")) end |
Instance Method Details
#all ⇒ Object
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 |
#each ⇒ Object
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 |