Class: TFA::Storage
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #all ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
-
#initialize(path) ⇒ Storage
constructor
A new instance of Storage.
- #save(key, value) ⇒ Object
- #secret_for(key) ⇒ Object
Constructor Details
#initialize(path) ⇒ Storage
Returns a new instance of Storage.
6 7 8 9 10 11 12 13 14 |
# File 'lib/tfa/storage.rb', line 6 def initialize(path) @path = path @storage = if ".pstore" == File.extname(path) PStore.new(path) else YAML::Store.new(path) end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/tfa/storage.rb', line 4 def path @path end |
Instance Method Details
#all ⇒ Object
22 23 24 25 26 |
# File 'lib/tfa/storage.rb', line 22 def all open_readonly do |storage| storage.roots.map { |key| { key => storage[key] } } end end |
#delete(key) ⇒ Object
40 41 42 43 44 |
# File 'lib/tfa/storage.rb', line 40 def delete(key) @storage.transaction do @storage.delete(key) end end |
#each ⇒ Object
16 17 18 19 20 |
# File 'lib/tfa/storage.rb', line 16 def each all.each do |each| yield each end end |
#save(key, value) ⇒ Object
34 35 36 37 38 |
# File 'lib/tfa/storage.rb', line 34 def save(key, value) @storage.transaction do @storage[key] = value end end |
#secret_for(key) ⇒ Object
28 29 30 31 32 |
# File 'lib/tfa/storage.rb', line 28 def secret_for(key) open_readonly do |storage| storage[key] end end |