Class: Etwin::Auth::UserAuthContext

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/etwin/auth/user_auth_context.rb

Overview

User authentication context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, user, is_administrator) ⇒ UserAuthContext

Returns a new instance of UserAuthContext.



23
24
25
26
27
28
# File 'lib/etwin/auth/user_auth_context.rb', line 23

def initialize(scope, user, is_administrator)
  @scope = T.let(scope, AuthScope)
  @user = T.let(user, Etwin::User::ShortUser)
  @is_administrator = T.let(is_administrator, T::Boolean)
  freeze
end

Instance Attribute Details

#is_administratorObject (readonly)

Returns the value of attribute is_administrator.



20
21
22
# File 'lib/etwin/auth/user_auth_context.rb', line 20

def is_administrator
  @is_administrator
end

#scopeObject (readonly)

Returns the value of attribute scope.



14
15
16
# File 'lib/etwin/auth/user_auth_context.rb', line 14

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user.



17
18
19
# File 'lib/etwin/auth/user_auth_context.rb', line 17

def user
  @user
end

Class Method Details

.deserialize(raw) ⇒ Object



74
75
76
77
78
79
# File 'lib/etwin/auth/user_auth_context.rb', line 74

def deserialize(raw)
  scope = AuthScope.deserialize(raw['scope'])
  user = Etwin::User::ShortUser.deserialize(raw['user'])
  is_administrator = raw['is_administrator']
  new(scope, user, is_administrator)
end

.from_json(json_str) ⇒ Object



69
70
71
# File 'lib/etwin/auth/user_auth_context.rb', line 69

def from_json(json_str)
  deserialize JSON.parse(json_str)
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/etwin/auth/user_auth_context.rb', line 31

def ==(other)
  case other
  when UserAuthContext
    @scope == other.scope && @user == other.user && @is_administrator == other.is_administrator
  else
    false
  end
end

#as_jsonObject



52
53
54
55
56
57
58
# File 'lib/etwin/auth/user_auth_context.rb', line 52

def as_json
  {
    'scope' => @scope.serialize,
    'user' => @user.as_json,
    'is_administrator' => @is_administrator
  }
end

#hashObject



41
42
43
# File 'lib/etwin/auth/user_auth_context.rb', line 41

def hash
  [@scope, @user, @is_administrator].hash
end

#inspectObject



61
62
63
# File 'lib/etwin/auth/user_auth_context.rb', line 61

def inspect
  "UserAuthContext(scope=#{@scope.inspect},user=#{@user.inspect},is_administrator=#{@is_administrator.inspect})"
end

#to_json(opts = nil) ⇒ Object



47
48
49
# File 'lib/etwin/auth/user_auth_context.rb', line 47

def to_json(opts = nil)
  JSON.generate(as_json, opts)
end