Sha256: be35b844df7d2c7df3c2037c478d3261ce30075bae73c2238d6011b66a2326c7

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Keycard::Request
  # 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.
  class AttributesFactory
    MODE_MAP = {
      direct:     DirectAttributes,
      proxy:      ProxiedAttributes,
      cosign:     CosignAttributes,
      shibboleth: ShibbolethAttributes
    }.freeze

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

    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

    private

    attr_reader :finders
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keycard-0.2.1 lib/keycard/request/attributes_factory.rb
keycard-0.2.0 lib/keycard/request/attributes_factory.rb