Class: Thron::User
Instance Attribute Summary collapse
-
#gateways ⇒ Object
readonly
Returns the value of attribute gateways.
-
#token_id ⇒ Object
readonly
Returns the value of attribute token_id.
Class Method Summary collapse
Instance Method Summary collapse
- #disguise(options) ⇒ Object
-
#initialize ⇒ User
constructor
A new instance of User.
- #logged? ⇒ Boolean
- #login(options) ⇒ Object
- #logout ⇒ Object
Constructor Details
#initialize ⇒ User
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
#gateways ⇒ Object (readonly)
Returns the value of attribute gateways.
25 26 27 |
# File 'lib/thron/user.rb', line 25 def gateways @gateways end |
#token_id ⇒ Object (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_gateways ⇒ Object
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 |
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() response = su() 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
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 login() @access_gateway.login().tap do |response| @token_id = @access_gateway.token_id refresh_gateways end end |
#logout ⇒ Object
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 |