Class: Htpasswd::Auths::Base
- Inherits:
-
Object
- Object
- Htpasswd::Auths::Base
- Defined in:
- lib/htpasswd/auths/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#authorize(entries) ⇒ Object
return authorized username or raise exception.
- #authorize_pass(pass) ⇒ Object
- #authorize_type(type) ⇒ Object
- #authorize_user(user) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #pass ⇒ Object
- #random(size = 16, array = nil) ⇒ Object
- #realm ⇒ Object
- #scheme ⇒ Object
- #set_controller(controller) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
56 57 58 |
# File 'lib/htpasswd/auths/base.rb', line 56 def initialize( = {}) @options = .with_indifferent_access end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
55 56 57 |
# File 'lib/htpasswd/auths/base.rb', line 55 def @options end |
Class Method Details
.<=>(other) ⇒ Object
50 51 52 |
# File 'lib/htpasswd/auths/base.rb', line 50 def <=> (other) strength <=> other.strength end |
.parse(data) ⇒ Object
46 47 48 |
# File 'lib/htpasswd/auths/base.rb', line 46 def parse(data) raise NotImplementedError, "subclass responsibility" end |
Instance Method Details
#authorize(entries) ⇒ Object
return authorized username or raise exception
61 62 63 64 65 66 67 68 |
# File 'lib/htpasswd/auths/base.rb', line 61 def (entries) entries.each do |entry| if user = entry.(self) return user end end raise UnknownUserAccount end |
#authorize_pass(pass) ⇒ Object
78 79 80 |
# File 'lib/htpasswd/auths/base.rb', line 78 def (pass) [:pass] == pass or raise IncorrectPassword end |
#authorize_type(type) ⇒ Object
70 71 72 |
# File 'lib/htpasswd/auths/base.rb', line 70 def (type) true end |
#authorize_user(user) ⇒ Object
74 75 76 |
# File 'lib/htpasswd/auths/base.rb', line 74 def (user) [:user] == user end |
#pass ⇒ Object
98 99 100 |
# File 'lib/htpasswd/auths/base.rb', line 98 def pass [:pass] end |
#random(size = 16, array = nil) ⇒ Object
102 103 104 105 |
# File 'lib/htpasswd/auths/base.rb', line 102 def random(size = 16, array = nil) array ||= (0..9).to_a + ('a'..'f').to_a (0...size).map{array[rand(array.size)]}.join end |
#realm ⇒ Object
86 87 88 |
# File 'lib/htpasswd/auths/base.rb', line 86 def realm [:realm] || Auths.default_realm end |
#scheme ⇒ Object
90 91 92 |
# File 'lib/htpasswd/auths/base.rb', line 90 def scheme self.class.name.demodulize end |
#set_controller(controller) ⇒ Object
82 83 84 |
# File 'lib/htpasswd/auths/base.rb', line 82 def set_controller(controller) # nop end |
#user ⇒ Object
94 95 96 |
# File 'lib/htpasswd/auths/base.rb', line 94 def user [:user] end |