class Rails::Auth::Credentials

Stores a set of credentials

Public Class Methods

from_rack_env(env) click to toggle source
# File lib/rails/auth/credentials.rb, line 15
def self.from_rack_env(env)
  new(env.fetch(Rails::Auth::Env::CREDENTIALS_ENV_KEY, {}))
end
new(credentials = {}) click to toggle source
# File lib/rails/auth/credentials.rb, line 19
def initialize(credentials = {})
  raise TypeError, "expected Hash, got #{credentials.class}" unless credentials.is_a?(Hash)

  @credentials = credentials
end

Public Instance Methods

[](type) click to toggle source
# File lib/rails/auth/credentials.rb, line 33
def [](type)
  @credentials[type.to_s]
end
[]=(type, value) click to toggle source
# File lib/rails/auth/credentials.rb, line 25
def []=(type, value)
  return if @credentials.key?(type) && @credentials[type] == value
  raise TypeError, "expected String for type, got #{type.class}" unless type.is_a?(String)
  raise AlreadyAuthorizedError, "credential '#{type}' has already been set" if @credentials.key?(type)

  @credentials[type] = value
end