Class: Thron::User

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/thron/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUser

Returns a new instance of User.



27
28
29
# File 'lib/thron/user.rb', line 27

def initialize
  @access_gateway = Gateway::AccessManager::new
end

Instance Attribute Details

#gatewaysObject (readonly)

Returns the value of attribute gateways.



25
26
27
# File 'lib/thron/user.rb', line 25

def gateways
  @gateways
end

#token_idObject (readonly)

Returns the value of attribute token_id.



25
26
27
# File 'lib/thron/user.rb', line 25

def token_id
  @token_id
end

Class Method Details

.delegate_to_gatewaysObject



16
17
18
19
20
21
# File 'lib/thron/user.rb', line 16

def self.delegate_to_gateways
  self.session_gateways.each do |name|
    gateway = Gateway.const_get(name)
    def_delegators "@gateways[:#{name}]", *(gateway.routes::keys + gateway.paginator_methods)
  end
end

.session_gatewaysObject



10
11
12
13
14
# File 'lib/thron/user.rb', line 10

def self.session_gateways
  @session_gateways ||= Gateway::constants.select do |name|
    Gateway.const_get(name) < Gateway::Session
  end
end

Instance Method Details

#disguise(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/thron/user.rb', line 44

def disguise(options)
  response = su(options)
  response.body[:id].tap do |token_id|
    return response.error unless token_id
    original_token, @token_id = @token_id, token_id
    refresh_gateways
    yield if block_given?
    @token_id = original_token 
    refresh_gateways
  end
end

#logged?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/thron/user.rb', line 56

def logged?
  !!@token_id
end

#login(options) ⇒ Object



31
32
33
34
35
36
# File 'lib/thron/user.rb', line 31

def (options)
  @access_gateway.(options).tap do |response|
    @token_id = @access_gateway.token_id
    refresh_gateways
  end
end

#logoutObject



38
39
40
41
42
# File 'lib/thron/user.rb', line 38

def logout
  return unless logged?
  @token_id = @access_gateway.token_id = nil
  @gateways = nil
end