Class: Kraut::Session

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::Validations, Mapper
Defined in:
app/models/kraut/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mapper

#initialize, #mass_assign!

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'app/models/kraut/session.rb', line 9

def password
  @password
end

#principalObject

Returns the value of attribute principal.



9
10
11
# File 'app/models/kraut/session.rb', line 9

def principal
  @principal
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'app/models/kraut/session.rb', line 9

def username
  @username
end

Class Method Details

.find_by_token(token) ⇒ Object



37
38
39
# File 'app/models/kraut/session.rb', line 37

def self.find_by_token(token)
  self.new(:principal => Kraut::Principal.find_by_token(token))
end

Instance Method Details

#allowed_to?(action) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/kraut/session.rb', line 20

def allowed_to?(action)
  in_group? Kraut::Rails::Engine.config.authorizations[action]
end

#in_group?(groups) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/kraut/session.rb', line 24

def in_group?(groups)
  Array.wrap(groups).any? { |group| principal.member_of? group }
end

#nameObject



12
13
14
# File 'app/models/kraut/session.rb', line 12

def name
  principal.name
end

#persisted?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/kraut/session.rb', line 41

def persisted?
  false
end

#tokenObject



16
17
18
# File 'app/models/kraut/session.rb', line 16

def token
  principal.token
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'app/models/kraut/session.rb', line 28

def valid?
  return unless super
  if self.principal.nil?
    login!
  else
    true
  end
end