Class: Passman::Manager
- Inherits:
-
Object
- Object
- Passman::Manager
- Defined in:
- lib/passman/manager.rb
Constant Summary collapse
- DEFAULT_PATH =
'passman.json'.freeze
Instance Method Summary collapse
- #add(account, username, password, key) ⇒ Object
- #delete(account) ⇒ Object
- #exist?(account) ⇒ Boolean
- #generate_password(length = 32) ⇒ Object
- #get(account, key) ⇒ Object
-
#initialize(file = nil) ⇒ Manager
constructor
A new instance of Manager.
- #list ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ Manager
Returns a new instance of Manager.
9 10 11 12 |
# File 'lib/passman/manager.rb', line 9 def initialize(file = nil) @file_path = DEFAULT_PATH @file_path = file unless file.nil? end |
Instance Method Details
#add(account, username, password, key) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/passman/manager.rb', line 18 def add(account, username, password, key) validate_add_arguments(account, username, password, key) db = database db[account.to_s] = { username: username, password: Passman::Crypto.encrypt(password, key) } store_data(db) end |
#delete(account) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/passman/manager.rb', line 25 def delete(account) raise ArgumentError, 'No account provided.' unless valid?(account) db = database db.delete(account.to_s) store_data(db) end |
#exist?(account) ⇒ Boolean
39 40 41 42 |
# File 'lib/passman/manager.rb', line 39 def exist?(account) raise ArgumentError, 'No account provided.' unless valid?(account) !(!database[account.to_s]) end |
#generate_password(length = 32) ⇒ Object
14 15 16 |
# File 'lib/passman/manager.rb', line 14 def generate_password(length = 32) Passman::PasswordGenerator.generate(length) end |
#get(account, key) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/passman/manager.rb', line 32 def get(account, key) validate_get_arguments(account, key) data = database[account.to_s] [account.to_s, { 'username' => data['username'], 'password' => Passman::Crypto.decrypt(data['password'], key) }] end |
#list ⇒ Object
44 45 46 |
# File 'lib/passman/manager.rb', line 44 def list database end |