Class: Kiss::Login

Inherits:
Hash show all
Defined in:
lib/kiss/login.rb

Instance Method Summary collapse

Methods inherited from Hash

#id, #method_missing, #prepend_html, #to_query_string, #type

Constructor Details

#initialize(session) ⇒ Login

Returns a new instance of Login.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/kiss/login.rb', line 3

def initialize(session)
  @_session = session
  @_session['login'] ||= {}
  
  # check if login expired
  if expired?
    # login expired
    @_session['login'] = {}
  end
  
  self.merge!(@_session['login'])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hash

Instance Method Details

#clearObject



39
40
41
42
# File 'lib/kiss/login.rb', line 39

def clear
  @_session['login'] = {}
  super()
end

#expired?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/kiss/login.rb', line 16

def expired?
  @_session['login']['expires_at'] && session['login']['expires_at'] < Time.now
end

#expires_at(time) ⇒ Object



25
26
27
# File 'lib/kiss/login.rb', line 25

def expires_at(time)
  persist(:expires_at => time)
end

#expires_at=(seconds) ⇒ Object



28
29
30
# File 'lib/kiss/login.rb', line 28

def expires_at=(seconds)
  expires_at(seconds)
end

#expires_in(seconds) ⇒ Object



32
33
34
# File 'lib/kiss/login.rb', line 32

def expires_in(seconds)
  persist(:expires_at => Time.now + seconds)
end

#expires_in=(seconds) ⇒ Object



35
36
37
# File 'lib/kiss/login.rb', line 35

def expires_in=(seconds)
  expires_in(seconds)
end

#persist(data = {}) ⇒ Object



20
21
22
23
# File 'lib/kiss/login.rb', line 20

def persist(data = {})
  @_session['login'].merge!(data)
  self.merge!(data)
end