class Thron::User

Attributes

gateways[R]
token_id[R]

Public Class Methods

delegate_to_gateways() click to toggle source
# 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
new() click to toggle source
# File lib/thron/user.rb, line 27
def initialize
  @access_gateway = Gateway::AccessManager::new
end
session_gateways() click to toggle source
# 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

Public Instance Methods

disguise(options) { || ... } click to toggle source
# 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?() click to toggle source
# File lib/thron/user.rb, line 56
def logged?
  !!@token_id
end
login(options) click to toggle source
# File lib/thron/user.rb, line 31
def login(options)
  @access_gateway.login(options).tap do |response|
    @token_id = @access_gateway.token_id
    refresh_gateways
  end
end
logout() click to toggle source
# File lib/thron/user.rb, line 38
def logout
  return unless logged?
  @token_id = @access_gateway.token_id = nil
  @gateways = nil
end

Private Instance Methods

initialize_gateways() click to toggle source
# File lib/thron/user.rb, line 62
def initialize_gateways
  self.class.session_gateways.reduce({}) do |acc, name|
    acc[name] = Gateway.const_get(name)::new(token_id: @token_id); acc
  end
end
refresh_gateways() click to toggle source
# File lib/thron/user.rb, line 68
def refresh_gateways
  return unless logged?
  return (@gateways = initialize_gateways) unless @gateways
  @access_gateway.token_id = @token_id
  @gateways.each do |name, gateway|
    gateway.token_id = @token_id
  end
end