Class: OmniauthOidc::ConfigFetcher::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/oidc/config_fetcher.rb

Overview

Config object with dynamic attribute access for OIDC discovery fields

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
# File 'lib/omniauth/oidc/config_fetcher.rb', line 8

def initialize(attributes = {})
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omniauth/oidc/config_fetcher.rb', line 29

def method_missing(method_name, *args)
  name = method_name.to_s

  if name.end_with?("=")
    key = name.chomp("=")
    @attributes[key.to_sym] = args.first
    @attributes[key] = args.first
  elsif @attributes.key?(name.to_sym)
    @attributes[name.to_sym]
  elsif @attributes.key?(name)
    @attributes[name]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/omniauth/oidc/config_fetcher.rb', line 12

def [](key)
  @attributes[key.to_sym] || @attributes[key.to_s]
end

#[]=(key, value) ⇒ Object



16
17
18
19
# File 'lib/omniauth/oidc/config_fetcher.rb', line 16

def []=(key, value)
  @attributes[key.to_sym] = value
  @attributes[key.to_s] = value
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/omniauth/oidc/config_fetcher.rb', line 21

def respond_to_missing?(method_name, include_private = false)
  setter = method_name.to_s.end_with?("=")
  key = setter ? method_name.to_s.chomp("=") : method_name.to_s
  setter || @attributes.key?(key.to_sym) || @attributes.key?(key) || super
end