Class: PasswordSafe::Keyring
- Inherits:
-
Object
- Object
- PasswordSafe::Keyring
show all
- Defined in:
- lib/passwordsafe/keyring.rb
Defined Under Namespace
Classes: KeyExistsException
Instance Method Summary
collapse
Constructor Details
#initialize(safe = nil) ⇒ Keyring
Returns a new instance of Keyring.
7
8
9
10
|
# File 'lib/passwordsafe/keyring.rb', line 7
def initialize safe = nil
@safe = safe
@ring = load_from_safe
end
|
Instance Method Details
#add(name, password) ⇒ Object
20
21
22
23
24
|
# File 'lib/passwordsafe/keyring.rb', line 20
def add name, password
raise KeyExistsException, "Key already exists in keyring, if you'd like to add it remove the existing key", caller if @ring.has_key?(name)
@ring.store(name, password)
@safe.write_safe @ring
end
|
#get(name) ⇒ Object
26
27
28
|
# File 'lib/passwordsafe/keyring.rb', line 26
def get name
@ring[name]
end
|
#has_a_safe? ⇒ Boolean
12
13
14
|
# File 'lib/passwordsafe/keyring.rb', line 12
def has_a_safe?
@safe.is_a? PasswordSafe::Safe
end
|
#length ⇒ Object
16
17
18
|
# File 'lib/passwordsafe/keyring.rb', line 16
def length
@ring.length
end
|
#list ⇒ Object
30
31
32
|
# File 'lib/passwordsafe/keyring.rb', line 30
def list
@ring.keys
end
|
#remove(name) ⇒ Object
34
35
36
37
|
# File 'lib/passwordsafe/keyring.rb', line 34
def remove name
@ring.delete(name)
@safe.write_safe @ring
end
|