Class: Rails::Auth::Credentials
- Inherits:
-
Object
- Object
- Rails::Auth::Credentials
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rails/auth/credentials.rb,
lib/rails/auth/credentials/injector_middleware.rb
Overview
Stores a set of credentials
Defined Under Namespace
Classes: InjectorMiddleware
Class Method Summary collapse
Instance Method Summary collapse
- #[](type) ⇒ Object
- #[]=(type, value) ⇒ Object
-
#initialize(credentials = {}) ⇒ Credentials
constructor
A new instance of Credentials.
Constructor Details
#initialize(credentials = {}) ⇒ Credentials
Returns a new instance of Credentials.
19 20 21 22 23 |
# 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 |
Class Method Details
.from_rack_env(env) ⇒ Object
15 16 17 |
# File 'lib/rails/auth/credentials.rb', line 15 def self.from_rack_env(env) new(env.fetch(Rails::Auth::Env::CREDENTIALS_ENV_KEY, {})) end |
Instance Method Details
#[](type) ⇒ Object
33 34 35 |
# File 'lib/rails/auth/credentials.rb', line 33 def [](type) @credentials[type.to_s] end |
#[]=(type, value) ⇒ Object
25 26 27 28 29 30 31 |
# 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 |