Module: Htpasswd::ClassMethods

Defined in:
lib/htpasswd/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#htdigest(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/htpasswd/class_methods.rb', line 43

def htdigest(options={})
  options = options.dup
  if options[:user] && options[:pass] && (options[:acl] || options[:type]) != :crypted && options[:class].blank?
    options[:pass] = Auths::Digest.new(options).a1
  end
  options[:scheme] = :digest
  options[:acl] ||= (options[:class] && :active_record)
  options[:acl] ||= (options[:file] ? :htdigest : :digest)

  htpasswd(options)
end

#htpasswd(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/htpasswd/class_methods.rb', line 18

def htpasswd(options={})
  options = options.dup
  options[:user] ||= options[:username]
  options[:pass] ||= options[:password]
  options[:acl]  ||= options[:type]

  if options[:exclusive]
    write_inheritable_array(:htpasswd_acls, [])
    write_inheritable_hash(:htpasswd_options, {})
  end

  (htpasswd_options[:schemes] ||= Set.new) << (options[:scheme] || :basic)

  options[:acl] ||= (options[:class] && :active_record)
  options[:acl] ||= (options[:file]  && :htpasswd)
  options[:acl] ||= (options[:user]  && options[:pass] && :plain)

  htpasswd_acls << Acls::Base[options[:acl]].new(options) if options[:acl]
  htpasswd_options.merge!(:realm=>options[:realm])        if options[:realm]

  skip_before_filter :htpasswd_authorize rescue nil
  delegate :htpasswd_options, :htpasswd_acls, :to=>"self.class" unless instance_methods.include?("htpasswd_options")
  before_filter :htpasswd_authorize
end

#htpasswd_aclsObject



59
60
61
# File 'lib/htpasswd/class_methods.rb', line 59

def htpasswd_acls
  read_inheritable_attribute(:htpasswd_acls) or write_inheritable_array(:htpasswd_acls, [])
end

#htpasswd_optionsObject



55
56
57
# File 'lib/htpasswd/class_methods.rb', line 55

def htpasswd_options
  read_inheritable_attribute(:htpasswd_options) or write_inheritable_hash(:htpasswd_options, {})
end