Class: Singularity::Profile
- Inherits:
-
Object
- Object
- Singularity::Profile
- Extended by:
- Forwardable
- Defined in:
- lib/singularity/profile.rb
Instance Attribute Summary collapse
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#initialize(identity, options = {}) ⇒ Profile
constructor
A new instance of Profile.
- #password?(value) ⇒ Boolean
- #password_hash ⇒ Object
- #password_hash=(value) ⇒ Object
- #password_iterations ⇒ Object
- #password_iterations=(value) ⇒ Object
- #password_salt ⇒ Object
- #password_salt=(value) ⇒ Object
Constructor Details
#initialize(identity, options = {}) ⇒ Profile
Returns a new instance of Profile.
11 12 13 14 15 16 17 |
# File 'lib/singularity/profile.rb', line 11 def initialize(identity, = {}) raise ArgumentError, "identity must be present" unless identity.to_s.length > 0 @prefix = .fetch(:prefix) { Singularity.profile_prefix } @identity = identity @redis = .fetch(:redis) { Redis.current } end |
Instance Attribute Details
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
9 10 11 |
# File 'lib/singularity/profile.rb', line 9 def identity @identity end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/singularity/profile.rb', line 9 def prefix @prefix end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
9 10 11 |
# File 'lib/singularity/profile.rb', line 9 def redis @redis end |
Instance Method Details
#password?(value) ⇒ Boolean
51 52 53 54 55 56 |
# File 'lib/singularity/profile.rb', line 51 def password?(value) return false unless password_hash.to_s.length > 0 return false unless password_salt.to_s.length > 0 PasswordHash.new(password_hash).matches?(value, password_salt, iterations: password_iterations) end |
#password_hash ⇒ Object
24 25 26 |
# File 'lib/singularity/profile.rb', line 24 def password_hash self['password_hash'] end |
#password_hash=(value) ⇒ Object
28 29 30 |
# File 'lib/singularity/profile.rb', line 28 def password_hash=(value) self['password_hash'] = value end |
#password_iterations ⇒ Object
40 41 42 43 44 45 |
# File 'lib/singularity/profile.rb', line 40 def password_iterations iters = self['password_iterations'].to_i iters = PasswordHash.iterations unless iters > 0 iters end |
#password_iterations=(value) ⇒ Object
47 48 49 |
# File 'lib/singularity/profile.rb', line 47 def password_iterations=(value) self['password_iterations'] = value end |
#password_salt ⇒ Object
32 33 34 |
# File 'lib/singularity/profile.rb', line 32 def password_salt self['password_salt'] end |
#password_salt=(value) ⇒ Object
36 37 38 |
# File 'lib/singularity/profile.rb', line 36 def password_salt=(value) self['password_salt'] = value end |