Module: AnotherApi::ApiTokenContract
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/another_api/api_token_contract.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #active? ⇒ Boolean
- #allows?(requested_scope) ⇒ Boolean
- #expired? ⇒ Boolean
- #parsed_scopes ⇒ Object
- #revoked? ⇒ Boolean
- #token_preview ⇒ Object
Instance Method Details
#active? ⇒ Boolean
17 18 19 |
# File 'lib/another_api/api_token_contract.rb', line 17 def active? !revoked? && !expired? end |
#allows?(requested_scope) ⇒ Boolean
9 10 11 |
# File 'lib/another_api/api_token_contract.rb', line 9 def allows?(requested_scope) parsed_scopes.any? { |s| s.matches?(requested_scope) } end |
#expired? ⇒ Boolean
25 26 27 |
# File 'lib/another_api/api_token_contract.rb', line 25 def expired? expires_at&.past? || false end |
#parsed_scopes ⇒ Object
13 14 15 |
# File 'lib/another_api/api_token_contract.rb', line 13 def parsed_scopes @parsed_scopes ||= scopes.map { |s| AnotherApi::Scope.parse(s) } end |
#revoked? ⇒ Boolean
21 22 23 |
# File 'lib/another_api/api_token_contract.rb', line 21 def revoked? revoked_at.present? end |
#token_preview ⇒ Object
29 30 31 |
# File 'lib/another_api/api_token_contract.rb', line 29 def token_preview "#{token_prefix}#{"*" * 12}#{token_suffix}" end |