Class HTAuth::DigestFile
In: lib/htauth/digest_file.rb
Parent: HTAuth::File

Methods

Constants

ENTRY_KLASS = HTAuth::DigestEntry

Public Instance methods

add an new record. raises an error if the entry exists.

[Source]

    # File lib/htauth/digest_file.rb, line 41
41:         def add(username, realm, password)
42:             raise DigestFileError, "Unable to add already existing user #{username} in realm #{realm}" if has_entry?(username, realm)
43:             
44:             new_entry = DigestEntry.new(username, realm, password)
45:             new_index = @lines.size
46:             @lines << new_entry.to_s
47:             @entries[new_entry.key] = { 'entry' => new_entry, 'line_index' => new_index }
48:             dirty!
49:             return nil
50:         end

add or update an entry as appropriate

[Source]

    # File lib/htauth/digest_file.rb, line 32
32:         def add_or_update(username, realm, password)
33:             if has_entry?(username, realm) then
34:                 update(username, realm, password)
35:             else
36:                 add(username, realm, password)
37:             end
38:         end

remove an entry from the file

[Source]

    # File lib/htauth/digest_file.rb, line 20
20:         def delete(username, realm)
21:             if has_entry?(username, realm) then
22:                 ir = internal_record(username, realm)
23:                 line_index = ir['line_index']
24:                 @entries.delete(ir['entry'].key)
25:                 @lines[line_index] = nil
26:                 dirty!
27:             end
28:             nil
29:         end

[Source]

    # File lib/htauth/digest_file.rb, line 70
70:         def entry_klass
71:             ENTRY_KLASS
72:         end

fetches a copy of an entry from the file. Updateing the entry returned from fetch will NOT propogate back to the file.

[Source]

    # File lib/htauth/digest_file.rb, line 64
64:         def fetch(username, realm)
65:             return nil unless has_entry?(username, realm)
66:             ir = internal_record(username, realm)
67:             return ir['entry'].dup
68:         end

[Source]

    # File lib/htauth/digest_file.rb, line 74
74:         def file_type
75:             "digest"
76:         end

does the entry the the specified username and realm exist in the file

[Source]

    # File lib/htauth/digest_file.rb, line 14
14:         def has_entry?(username, realm)
15:             test_entry = DigestEntry.new(username, realm)
16:             @entries.has_key?(test_entry.key)
17:         end

update an already existing entry with a new password. raises an error if the entry does not exist

[Source]

    # File lib/htauth/digest_file.rb, line 53
53:         def update(username, realm, password)
54:             raise DigestFileError, "Unable to update non-existent user #{username} in realm #{realm}" unless has_entry?(username, realm)
55:             ir = internal_record(username, realm)
56:             ir['entry'].password = password
57:             @lines[ir['line_index']] = ir['entry'].to_s
58:             dirty!
59:             return nil
60:         end

[Validate]