Class: TOTP::CLI::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/totp/cli/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#storeObject

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_allObject



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