Class: Singularity::Profile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/singularity/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identity, options = {}) ⇒ Profile

Returns a new instance of Profile.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
# File 'lib/singularity/profile.rb', line 12

def initialize(identity, options = {})
  raise ArgumentError, "identity must be present" unless identity.to_s.length > 0

  @prefix       = options.fetch(:prefix) { Singularity.profile_prefix }
  @identity     = identity
  @redis        = options.fetch(:redis) { Redis.current }
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



10
11
12
# File 'lib/singularity/profile.rb', line 10

def identity
  @identity
end

#prefixObject (readonly)

Returns the value of attribute prefix.



10
11
12
# File 'lib/singularity/profile.rb', line 10

def prefix
  @prefix
end

#redisObject (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

Returns:

  • (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_hashObject



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_iterationsObject



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_saltObject



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