Class: Ya::Directory
- Inherits:
-
Object
- Object
- Ya::Directory
- Defined in:
- lib/ya/directory.rb
Instance Method Summary collapse
- #add(login, password, attrs = {}) ⇒ Object
- #authenticate(login, password) ⇒ Object
-
#initialize(directory_file) ⇒ Directory
constructor
A new instance of Directory.
- #lookup(login) ⇒ Object
- #mod(login, attrs = {}) ⇒ Object
- #remove(login) ⇒ Object
- #reset(login, new_password) ⇒ Object
Constructor Details
#initialize(directory_file) ⇒ Directory
Returns a new instance of Directory.
4 5 6 7 |
# File 'lib/ya/directory.rb', line 4 def initialize(directory_file) @directory_file = directory_file FileUtils.touch(@directory_file) end |
Instance Method Details
#add(login, password, attrs = {}) ⇒ Object
21 22 23 |
# File 'lib/ya/directory.rb', line 21 def add(login, password, attrs = {}) dump_record(login.to_sym => Digest.salt_and_hash(password).merge(attrs)) end |
#authenticate(login, password) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ya/directory.rb', line 14 def authenticate(login, password) record = lookup(login) return nil unless record challenge = Digest.salt_password(record[:salt], password) challenge == record[:hash] ? record.merge(:login => login) : false end |
#lookup(login) ⇒ Object
9 10 11 12 |
# File 'lib/ya/directory.rb', line 9 def lookup(login) return unless login load[login.to_sym] end |
#mod(login, attrs = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/ya/directory.rb', line 25 def mod(login, attrs = {}) record = lookup(login) return nil unless record dump_record(login.to_sym => record.merge(attrs)) end |
#remove(login) ⇒ Object
37 38 39 40 |
# File 'lib/ya/directory.rb', line 37 def remove(login) dictionary = load dictionary.delete(login.to_sym) ? dump(dictionary) : false end |
#reset(login, new_password) ⇒ Object
31 32 33 34 35 |
# File 'lib/ya/directory.rb', line 31 def reset(login, new_password) record = lookup(login) return nil unless record dump_record(login.to_sym => record.merge(Digest.salt_and_hash(new_password))) end |