Sha256: 83eccd400aa17e0edd901c53906788f5847e1c89d5aa214e1e37176bbe4dee4b

Contents?: true

Size: 1.35 KB

Versions: 105

Compression:

Stored size: 1.35 KB

Contents

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

105 entries across 100 versions & 16 rubygems

Version Path
devise-4.3.0 lib/devise/omniauth/config.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/devise-4.2.1/lib/devise/omniauth/config.rb
devise-4.2.1 lib/devise/omniauth/config.rb
devise-4.2.0 lib/devise/omniauth/config.rb
devise-3.5.10 lib/devise/omniauth/config.rb
devise-4.0.3 lib/devise/omniauth/config.rb
devise-4.1.1 lib/devise/omniauth/config.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/lib/devise/omniauth/config.rb
devise-4.1.0 lib/devise/omniauth/config.rb
devise-3.5.9 lib/devise/omniauth/config.rb
devise-4.0.2 lib/devise/omniauth/config.rb
devise-4.0.1 lib/devise/omniauth/config.rb
devise-3.5.8 lib/devise/omniauth/config.rb
devise-3.5.7 lib/devise/omniauth/config.rb
devise-4.0.0 lib/devise/omniauth/config.rb
devise-4.0.0.rc2 lib/devise/omniauth/config.rb
devise-4.0.0.rc1 lib/devise/omniauth/config.rb
devise-3.5.6 lib/devise/omniauth/config.rb
devise-3.5.5 lib/devise/omniauth/config.rb
devise-3.5.4 lib/devise/omniauth/config.rb