Class: NebulaToken::RefreshResult

Inherits:
Object
  • Object
show all
Defined in:
lib/nebula_token.rb

Overview

Result of Engine#refresh ([N-29]: outcomes are values, never exceptions).

user_id and family_id are populated whenever the engine resolved a record — every code except MALFORMED, UNKNOWN_KID and NOT_FOUND — so a REUSE_DETECTED or DEVICE_MISMATCH event can be attributed to a session without a second lookup of a token you were told never to log ([N-39]).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ok:, token: nil, user_id: nil, family_id: nil, generation: nil, expires_at: nil, idle_expires_at: nil, error: nil) ⇒ RefreshResult

rubocop:disable Metrics/ParameterLists



528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/nebula_token.rb', line 528

def initialize(ok:, token: nil, user_id: nil, family_id: nil, generation: nil,
               expires_at: nil, idle_expires_at: nil, error: nil)
  @ok = ok
  @token = token
  @user_id = user_id
  @family_id = family_id
  @generation = generation
  @expires_at = expires_at
  @idle_expires_at = idle_expires_at
  @error = error
  freeze
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



525
526
527
# File 'lib/nebula_token.rb', line 525

def error
  @error
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



525
526
527
# File 'lib/nebula_token.rb', line 525

def expires_at
  @expires_at
end

#family_idObject (readonly)

Returns the value of attribute family_id.



525
526
527
# File 'lib/nebula_token.rb', line 525

def family_id
  @family_id
end

#generationObject (readonly)

Returns the value of attribute generation.



525
526
527
# File 'lib/nebula_token.rb', line 525

def generation
  @generation
end

#idle_expires_atObject (readonly)

Returns the value of attribute idle_expires_at.



525
526
527
# File 'lib/nebula_token.rb', line 525

def idle_expires_at
  @idle_expires_at
end

#tokenObject (readonly)

Returns the value of attribute token.



525
526
527
# File 'lib/nebula_token.rb', line 525

def token
  @token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



525
526
527
# File 'lib/nebula_token.rb', line 525

def user_id
  @user_id
end

Class Method Details

.failure(error, record = nil) ⇒ Object

record is nil exactly when nothing was resolved ([N-39]).



550
551
552
# File 'lib/nebula_token.rb', line 550

def self.failure(error, record = nil)
  new(ok: false, error: error, user_id: record&.user_id, family_id: record&.family_id)
end

.success(token:, user_id:, family_id:, generation:, expires_at:, idle_expires_at:) ⇒ Object



544
545
546
547
# File 'lib/nebula_token.rb', line 544

def self.success(token:, user_id:, family_id:, generation:, expires_at:, idle_expires_at:)
  new(ok: true, token: token, user_id: user_id, family_id: family_id,
      generation: generation, expires_at: expires_at, idle_expires_at: idle_expires_at)
end

Instance Method Details

#inspectObject Also known as: to_s

[N-14], as for IssueResult.



555
556
557
558
559
# File 'lib/nebula_token.rb', line 555

def inspect
  "#<NebulaToken::RefreshResult ok=#{@ok} error=#{@error.inspect} " \
    "user_id=#{@user_id.inspect} family_id=#{@family_id.inspect} " \
    "generation=#{@generation.inspect} token=#{@token.nil? ? 'nil' : '[REDACTED]'}>"
end

#ok?Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


542
# File 'lib/nebula_token.rb', line 542

def ok? = @ok