Class: Etwin::Auth::AccessTokenAuthContext

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

Overview

Access token authentication context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, client, user) ⇒ AccessTokenAuthContext

Returns a new instance of AccessTokenAuthContext.



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

def initialize(scope, client, user)
  @scope = T.let(scope, AuthScope)
  @client = T.let(client, Etwin::Oauth::ShortOauthClient)
  @user = T.let(user, Etwin::User::ShortUser)
  freeze
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Class Method Details

.deserialize(raw) ⇒ Object



94
95
96
97
98
99
# File 'lib/etwin/auth/access_token_auth_context.rb', line 94

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

.from_json(json_str) ⇒ Object



89
90
91
# File 'lib/etwin/auth/access_token_auth_context.rb', line 89

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/access_token_auth_context.rb', line 31

def ==(other)
  case other
  when AccessTokenAuthContext
    @scope == other.scope && @client == other.client && @user == other.user
  else
    false
  end
end

#as_jsonObject



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

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

#hashObject



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

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

#inspectObject



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

def inspect
  PP.singleline_pp(self, String.new)
end

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/etwin/auth/access_token_auth_context.rb', line 66

def pretty_print(pp)  # rubocop:disable Metrics/MethodLength
pp.group(0, "#{self.class.name}(", ')') do
  pp.nest 1 do
    pp.breakable ''
    pp.text 'scope='
    pp.pp @scope
    pp.text ','
    pp.breakable ''
    pp.text 'client='
    pp.pp @client
    pp.text ','
    pp.breakable ''
    pp.text 'user='
    pp.pp @user
  end
  pp.breakable ''
end
end

#to_json(opts = nil) ⇒ Object



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

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