Class: YiffSpace::Auth::AuthInfo
- Inherits:
-
Object
- Object
- YiffSpace::Auth::AuthInfo
- Defined in:
- lib/yiffspace/auth/auth_info.rb,
lib/yiffspace/auth/auth_info/anonymous.rb
Defined Under Namespace
Classes: Anonymous
Instance Attribute Summary collapse
-
#entitlements ⇒ Object
readonly
Returns the value of attribute entitlements.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #blank? ⇒ Boolean
- #has_permission?(name) ⇒ Boolean
-
#initialize(id:, entitlements:, roles:, token:) ⇒ AuthInfo
constructor
A new instance of AuthInfo.
-
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything.
- #serializable_hash ⇒ Object
- #to_session ⇒ Object
Constructor Details
#initialize(id:, entitlements:, roles:, token:) ⇒ AuthInfo
Returns a new instance of AuthInfo.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yiffspace/auth/auth_info.rb', line 12 def initialize(id:, entitlements:, roles:, token:) raise(ArgumentError, "no id provided") if id.blank? raise(ArgumentError, "no token provided") if token.blank? @id = id @token = token @entitlements = Array(entitlements) @roles = Array(roles) @permissions = Permissions.new(@entitlements) end |
Instance Attribute Details
#entitlements ⇒ Object (readonly)
Returns the value of attribute entitlements.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def entitlements @entitlements end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def id @id end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def @permissions end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def roles @roles end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def token @token end |
Class Method Details
.from_json(data) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/yiffspace/auth/auth_info.rb', line 53 def self.from_json(data) raise(ArgumentError, "invalid data") if data.blank? data = JSON.parse(data) if data.is_a?(String) data = ::YiffSpace::Utils::OpenHash.from(data) new( id: data.id, token: ::YiffSpace::Auth.unserialize_token(data.token), entitlements: data.entitlements, roles: data.roles, ) end |
.from_session(data) ⇒ Object
67 68 69 70 71 |
# File 'lib/yiffspace/auth/auth_info.rb', line 67 def self.from_session(data) return nil if data.blank? from_json(data) end |
Instance Method Details
#anonymous? ⇒ Boolean
23 24 25 |
# File 'lib/yiffspace/auth/auth_info.rb', line 23 def anonymous? false end |
#blank? ⇒ Boolean
32 33 34 |
# File 'lib/yiffspace/auth/auth_info.rb', line 32 def blank? false end |
#has_permission?(name) ⇒ Boolean
36 37 38 |
# File 'lib/yiffspace/auth/auth_info.rb', line 36 def (name) .include?(name.to_s) end |
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything
28 29 30 |
# File 'lib/yiffspace/auth/auth_info.rb', line 28 def present? true end |
#serializable_hash ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/yiffspace/auth/auth_info.rb', line 40 def serializable_hash(*) { "id" => id, "token" => ::YiffSpace::Auth.serialize_token(token), "entitlements" => entitlements, "roles" => roles, } end |
#to_session ⇒ Object
49 50 51 |
# File 'lib/yiffspace/auth/auth_info.rb', line 49 def to_session serializable_hash end |