Class: Fragmentary::SessionUser

Inherits:
Object
  • Object
show all
Defined in:
lib/fragmentary/session_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_type, options = {}) ⇒ SessionUser

Returns a new instance of SessionUser.



30
31
32
33
# File 'lib/fragmentary/session_user.rb', line 30

def initialize(user_type, options={})
  @user_type = user_type   # this probably not really necessary
  @options = options
end

Instance Attribute Details

#user_typeObject (readonly)

Returns the value of attribute user_type.



5
6
7
# File 'lib/fragmentary/session_user.rb', line 5

def user_type
  @user_type
end

Class Method Details

.create(user_type, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fragmentary/session_user.rb', line 17

def self.create(user_type, options={})
  user_group = options[:group] || options[:user_group] || 'default'
  if user = fetch(user_type, user_group)
    raise RangeError, "You can't redefine an existing SessionUser object: #{user_type.inspect}" unless user.options == options
  else
    @user_type = user_type   # this probably not really necessary
    @options = options
    user = new(user_type, options)
    all[user_type].merge!(user_group => user)
  end
  user
end

.fetch(user_type, user_group = 'default') ⇒ Object



13
14
15
# File 'lib/fragmentary/session_user.rb', line 13

def self.fetch(user_type, user_group = 'default')
  all[user_type][user_group]
end

Instance Method Details

#credentialsObject



35
36
37
# File 'lib/fragmentary/session_user.rb', line 35

def credentials
  options[:credentials]
end