Class: Negroni::OmniAuth::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/negroni/omniauth/config.rb

Overview

Config encapsulates OmniAuth configuration for Negroni

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, args) ⇒ Config

Create a new OmniAuth::Config

Parameters:

  • provider (Symbol)

    the name of the provider to use

  • args (Array<Object>)

    any arguments to pass to the provider



44
45
46
47
48
49
50
51
# File 'lib/negroni/omniauth/config.rb', line 44

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



24
25
26
# File 'lib/negroni/omniauth/config.rb', line 24

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/negroni/omniauth/config.rb', line 28

def options
  @options
end

#providerObject (readonly)

Returns the value of attribute provider.



32
33
34
# File 'lib/negroni/omniauth/config.rb', line 32

def provider
  @provider
end

#strategySymbol

Returns the strategy for OmniAuth.

Returns:

  • (Symbol)

    the strategy for OmniAuth



20
21
22
# File 'lib/negroni/omniauth/config.rb', line 20

def strategy
  @strategy
end

#strategy_classClass (readonly)

Returns the class for the OmniAuth strategy.

Returns:

  • (Class)

    the class for the OmniAuth strategy



# File 'lib/negroni/omniauth/config.rb', line 53

#strategy_nameObject (readonly)

Returns the value of attribute strategy_name.



37
38
39
# File 'lib/negroni/omniauth/config.rb', line 37

def strategy_name
  @strategy_name
end

Instance Method Details

#autoload_strategyObject

Autoload a strategy

Raises:



70
71
72
73
74
75
76
77
78
# File 'lib/negroni/omniauth/config.rb', line 70

def autoload_strategy
  name = ::OmniAuth::Utils.camelize(provider.to_s)

  if ::OmniAuth::Strategies.const_defined?(name)
    return ::OmniAuth::Strategies.const_get(name)
  end

  raise UnknownStrategy, name
end

#find_strategyObject

Find a the strategy, using the name provided



62
63
64
65
66
67
# File 'lib/negroni/omniauth/config.rb', line 62

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