Class: TOTP::CLI::Store
- Inherits:
-
Object
- Object
- TOTP::CLI::Store
- Defined in:
- lib/totp/cli/store.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(file) ⇒ Store
constructor
A new instance of Store.
- #read_all ⇒ Object
- #remove(label) ⇒ Object
- #save(label, secret) ⇒ Object
Constructor Details
#initialize(file) ⇒ Store
Returns a new instance of Store.
8 9 10 |
# File 'lib/totp/cli/store.rb', line 8 def initialize(file) @store = PStore.new(file) end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
6 7 8 |
# File 'lib/totp/cli/store.rb', line 6 def store @store end |
Instance Method Details
#read_all ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/totp/cli/store.rb', line 12 def read_all tokens = [] store.transaction(true) do store.roots.each_with_index do |label, index| tokens << Token.new(id: index, label: label, secret: store[label]) end end tokens end |
#remove(label) ⇒ Object
32 33 34 35 36 |
# File 'lib/totp/cli/store.rb', line 32 def remove(label) store.transaction do store.delete(label) end end |
#save(label, secret) ⇒ Object
26 27 28 29 30 |
# File 'lib/totp/cli/store.rb', line 26 def save(label, secret) store.transaction do store[label] = secret end end |