Module: Genius::Auth
- Defined in:
- lib/genius/api/authorization.rb
Overview
Genius::Auth module is used to authenticate users with their token. It provides initialization of token instance variable.
Class Method Summary collapse
-
.authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}") ⇒ Boolean
Genius::Auth.authorized?-> true or false. -
.logout! ⇒ NilClass
Genius::Auth.logout!-> NilClass. -
.token=(token) ⇒ String
(also: login=)
Genius::Auth.token=-> true or false.
Class Method Details
.authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}") ⇒ Boolean
somehow detect exceptions as boolean type
Genius::Auth.authorized? -> true or false
authorized? method checks if user in current session is authorized.
36 37 38 39 40 41 42 |
# File 'lib/genius/api/authorization.rb', line 36 def (token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}") Errors.validate_token(token, method_name: method_name) rescue Genius::Errors::TokenError false else true end |
.logout! ⇒ NilClass
Genius::Auth.logout! -> NilClass
logout! method modifies a token object and revoke session by setting nil to the token.
50 51 52 |
# File 'lib/genius/api/authorization.rb', line 50 def logout! @token = nil unless @token.nil? end |
.token=(token) ⇒ String Also known as: login=
Genius::Auth.token= -> true or false
Genius::Auth.token= is a setter which handles all possible exceptions under the hood during authentication. It means that you should never use token= method unless you actually know that your credentials are valid (not recommended).
22 23 24 25 |
# File 'lib/genius/api/authorization.rb', line 22 def token=(token) Genius::Errors.validate_token(token) @token = token end |