Module: Devise::OmniAuth::UrlHelpers

Defined in:
lib/devise/omniauth/url_helpers.rb

Class Method Summary collapse

Class Method Details

.define_helpers(mapping) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/devise/omniauth/url_helpers.rb', line 4

def self.define_helpers(mapping)
  return unless mapping.omniauthable?
  method = "#{mapping.name}_omniauth_authorize_path"

  class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
    def #{method}(provider, params = {})
      if Devise.omniauth_configs[provider.to_sym]
        script_name = request.env["SCRIPT_NAME"]

        path = "\#{script_name}/#{mapping.path}/auth/\#{provider}\".squeeze("/")
        path << '?' + params.to_param if params.present?
        path
      else
        raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
      end
    end
    protected :#{method}
  URL_HELPERS
end