Class: Pechkin::Auth::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/auth.rb

Overview

Utility class for altering htpasswd files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(htpasswd) ⇒ Manager

Returns a new instance of Manager.



9
10
11
# File 'lib/pechkin/auth.rb', line 9

def initialize(htpasswd)
  @htpasswd = htpasswd
end

Instance Attribute Details

#htpasswdObject (readonly)

Returns the value of attribute htpasswd.



7
8
9
# File 'lib/pechkin/auth.rb', line 7

def htpasswd
  @htpasswd
end

Instance Method Details

#add(user, password) ⇒ Object



13
14
15
16
17
18
# File 'lib/pechkin/auth.rb', line 13

def add(user, password)
  m = File.exist?(htpasswd) ? HTAuth::File::ALTER : HTAuth::File::CREATE
  HTAuth::PasswdFile.open(htpasswd, m) do |f|
    f.add_or_update(user, password, 'md5')
  end
end