Class: OmniAuth::Builder

Inherits:
Rack::Builder
  • Object
show all
Defined in:
lib/omniauth/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
9
10
11
12
# File 'lib/omniauth/builder.rb', line 5

def initialize(app, &block)
  if rack14?
    super
  else
    @app = app
    super(&block)
  end
end

Instance Method Details

#call(env) ⇒ Object



40
41
42
43
# File 'lib/omniauth/builder.rb', line 40

def call(env)
  @ins << @app unless rack14? || @ins.include?(@app)
  to_app.call(env)
end

#configure(&block) ⇒ Object



22
23
24
# File 'lib/omniauth/builder.rb', line 22

def configure(&block)
  OmniAuth.configure(&block)
end

#on_failure(&block) ⇒ Object



18
19
20
# File 'lib/omniauth/builder.rb', line 18

def on_failure(&block)
  OmniAuth.config.on_failure = block
end

#provider(klass, *args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/omniauth/builder.rb', line 26

def provider(klass, *args, &block)
  if klass.is_a?(Class)
    middleware = klass
  else
    begin
      middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
    rescue NameError
      raise LoadError, "Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."
    end
  end

  use middleware, *args, &block
end

#rack14?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/omniauth/builder.rb', line 14

def rack14?
  Rack.release.split('.')[1].to_i >= 4
end