Sha256: 34caf51accdd26b42fa1a206166d65bed0b6d4b8e24d8cf88df2d766a05a0e44

Contents?: true

Size: 1.38 KB

Versions: 22

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Devise
  module OmniAuth
    class StrategyNotFound < NameError
      def initialize(strategy)
        @strategy = strategy
        super("Could not find a strategy with name `#{strategy}'. " \
          "Please ensure it is required or explicitly set it using the :strategy_class option.")
      end
    end

    class Config
      attr_accessor :strategy
      attr_reader :args, :options, :provider, :strategy_name

      def initialize(provider, args)
        @provider       = provider
        @args           = args
        @options        = @args.last.is_a?(Hash) ? @args.last : {}
        @strategy       = nil
        @strategy_name  = options[:name] || @provider
        @strategy_class = options.delete(:strategy_class)
      end

      def strategy_class
        @strategy_class ||= find_strategy || autoload_strategy
      end

      def find_strategy
        ::OmniAuth.strategies.find do |strategy_class|
          strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
            strategy_class.default_options[:name] == strategy_name
        end
      end

      def autoload_strategy
        name = ::OmniAuth::Utils.camelize(provider.to_s)
        if ::OmniAuth::Strategies.const_defined?(name)
          ::OmniAuth::Strategies.const_get(name)
        else
          raise StrategyNotFound, name
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/devise-4.9.4/lib/devise/omniauth/config.rb
devise-4.9.4 lib/devise/omniauth/config.rb
devise-4.9.3 lib/devise/omniauth/config.rb
devise-4.9.2 lib/devise/omniauth/config.rb
devise-4.9.1 lib/devise/omniauth/config.rb
devise-4.9.0 lib/devise/omniauth/config.rb
devise-4.8.1 lib/devise/omniauth/config.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/devise-4.8.0/lib/devise/omniauth/config.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/devise-4.8.0/lib/devise/omniauth/config.rb
devise-4.8.0 lib/devise/omniauth/config.rb
devise-4.7.3 lib/devise/omniauth/config.rb
devise-4.7.2 lib/devise/omniauth/config.rb
devise-4.7.1 lib/devise/omniauth/config.rb
devise-4.7.0 lib/devise/omniauth/config.rb
devise-4.6.2 lib/devise/omniauth/config.rb
devise-4.6.1 lib/devise/omniauth/config.rb
devise-4.6.0 lib/devise/omniauth/config.rb
devise-4.5.0 lib/devise/omniauth/config.rb
devise-4.4.3 lib/devise/omniauth/config.rb
devise-4.4.2 lib/devise/omniauth/config.rb