Class: Fragmentary::SessionUser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SessionUser.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fragmentary/session_user.rb', line 13

def initialize(user_type, options={})
  if user = self.class.fetch(user_type)
    if user.options != options
      raise RangeError, "You can't redefine an existing SessionUser object: #{user_type.inspect}"
    else
      user
    end
  else
    @user_type = user_type
    @options = options
    self.class.all.merge!({user_type => self})
  end
end

Class Method Details

.allObject



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

def self.all
  @@all ||= Hash.new
end

.fetch(key) ⇒ Object



9
10
11
# File 'lib/fragmentary/session_user.rb', line 9

def self.fetch(key)
  all[key]
end

Instance Method Details

#credentialsObject



27
28
29
# File 'lib/fragmentary/session_user.rb', line 27

def credentials
  options[:credentials]
end