Class: Keycard::Request::AttributesFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/keycard/request/attributes_factory.rb

Overview

Factory to simplify creation of Attributes instances. It binds in a list of finders and inspects the Keycard.config.access mode to determine which subclass to use. You can register a factory instance as a service and then use .for instead of naming concrete classes when processing requests.

Constant Summary collapse

MODE_MAP =
{
  direct:     DirectAttributes,
  proxy:      ProxiedAttributes,
  cosign:     CosignAttributes,
  shibboleth: ShibbolethAttributes
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(finders: [Keycard::InstitutionFinder.new]) ⇒ AttributesFactory

Returns a new instance of AttributesFactory.



16
17
18
# File 'lib/keycard/request/attributes_factory.rb', line 16

def initialize(finders: [Keycard::InstitutionFinder.new])
  @finders = finders
end

Instance Method Details

#for(request) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/keycard/request/attributes_factory.rb', line 20

def for(request)
  mode = MODE_MAP[Keycard.config.access.to_sym]
  if mode.nil?
    # TODO: Warn about this once to the appropriate log; probably in a config check, not here.
    # puts "Keycard does not recognize the '#{access}' access mode, using 'direct'."
    mode = DirectAttributes
  end
  mode.new(request, finders: finders)
end