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
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#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:, roles:, permissions:, token:, client_id:) ⇒ 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:, roles:, permissions:, token:, client_id:) ⇒ AuthInfo
Returns a new instance of AuthInfo.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yiffspace/auth/auth_info.rb', line 13 def initialize(id:, roles:, permissions:, token:, client_id:) raise(ArgumentError, "no id provided") if id.blank? raise(ArgumentError, "no token provided") if token.blank? raise(ArgumentError, "no client id provided") if client_id.blank? @id = id @token = token @roles = Array(roles) @permissions = Permissions.new(, separator: YiffSpace::Auth.get_by_id(client_id).) @client_id = client_id end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/yiffspace/auth/auth_info.rb', line 6 def client_id @client_id 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/yiffspace/auth/auth_info.rb', line 56 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: data.token, roles: data.roles, permissions: data., client_id: data.client_id, ) end |
.from_session(data) ⇒ Object
71 72 73 74 75 |
# File 'lib/yiffspace/auth/auth_info.rb', line 71 def self.from_session(data) return nil if data.blank? from_json(data) end |
Instance Method Details
#anonymous? ⇒ Boolean
25 26 27 |
# File 'lib/yiffspace/auth/auth_info.rb', line 25 def anonymous? false end |
#blank? ⇒ Boolean
34 35 36 |
# File 'lib/yiffspace/auth/auth_info.rb', line 34 def blank? false end |
#has_permission?(name) ⇒ Boolean
38 39 40 |
# File 'lib/yiffspace/auth/auth_info.rb', line 38 def (name) .include?(name.to_s) end |
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything
30 31 32 |
# File 'lib/yiffspace/auth/auth_info.rb', line 30 def present? true end |
#serializable_hash ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/yiffspace/auth/auth_info.rb', line 42 def serializable_hash(*) { "id" => id, "token" => token.as_json, "roles" => roles, "permissions" => .values, "client_id" => client_id, } end |
#to_session ⇒ Object
52 53 54 |
# File 'lib/yiffspace/auth/auth_info.rb', line 52 def to_session serializable_hash end |