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.
12 13 14 15 16 17 18 |
# File 'lib/singularity/profile.rb', line 12 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.
10 11 12 |
# File 'lib/singularity/profile.rb', line 10 def identity @identity end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/singularity/profile.rb', line 10 def prefix @prefix end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
10 11 12 |
# File 'lib/singularity/profile.rb', line 10 def redis @redis end |
Instance Method Details
#password?(value) ⇒ Boolean
52 53 54 55 56 57 |
# File 'lib/singularity/profile.rb', line 52 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
25 26 27 |
# File 'lib/singularity/profile.rb', line 25 def password_hash self['password_hash'] end |
#password_hash=(value) ⇒ Object
29 30 31 |
# File 'lib/singularity/profile.rb', line 29 def password_hash=(value) self['password_hash'] = value end |
#password_iterations ⇒ Object
41 42 43 44 45 46 |
# File 'lib/singularity/profile.rb', line 41 def password_iterations iters = self['password_iterations'].to_i iters = PasswordHash.iterations unless iters > 0 iters end |
#password_iterations=(value) ⇒ Object
48 49 50 |
# File 'lib/singularity/profile.rb', line 48 def password_iterations=(value) self['password_iterations'] = value end |
#password_salt ⇒ Object
33 34 35 |
# File 'lib/singularity/profile.rb', line 33 def password_salt self['password_salt'] end |
#password_salt=(value) ⇒ Object
37 38 39 |
# File 'lib/singularity/profile.rb', line 37 def password_salt=(value) self['password_salt'] = value end |