1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Camelizations are now added through OmniAuth.config

This commit is contained in:
Michael Bleigh 2011-09-22 18:49:22 -05:00
parent 69177f3b10
commit 98bc2b9a4a
2 changed files with 12 additions and 27 deletions

View file

@ -18,6 +18,7 @@ module OmniAuth
include Singleton
@@defaults = {
:camelizations => {},
:path_prefix => '/auth',
:on_failure => Proc.new do |env|
message_key = env['omniauth.error.type']
@ -31,9 +32,7 @@ module OmniAuth
:default => {
'provider' => 'default',
'uid' => '1234',
'user_info' => {
'name' => 'Bob Example'
}
'name' => 'Bob Example'
}
}
}
@ -75,8 +74,12 @@ module OmniAuth
self.mock_auth[provider.to_sym] = mock
end
def add_camelization(name, camelized)
self.camelizations[name.to_s] = camelized.to_s
end
attr_writer :on_failure
attr_accessor :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host
attr_accessor :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations
end
def self.config
@ -92,21 +95,6 @@ module OmniAuth
end
module Utils
CAMELIZE_SPECIAL = {
'oauth' => 'OAuth',
'oauth2' => 'OAuth2',
'openid' => 'OpenID',
'open_id' => 'OpenID',
'github' => 'GitHub',
'tripit' => 'TripIt',
'soundcloud' => 'SoundCloud',
'smugmug' => 'SmugMug',
'cas' => 'CAS',
'trademe' => 'TradeMe',
'ldap' => 'LDAP',
'google_oauth2' => 'GoogleOAuth2'
}
module_function
def form_css
@ -129,7 +117,7 @@ module OmniAuth
end
def camelize(word, first_letter_in_uppercase = true)
return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s]
return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
if first_letter_in_uppercase
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }

View file

@ -1,4 +1,4 @@
require File.expand_path('../../spec_helper', __FILE__)
require 'spec_helper'
describe OmniAuth do
describe '.strategies' do
@ -67,12 +67,9 @@ describe OmniAuth do
}.each_pair{ |k,v| OmniAuth::Utils.camelize(k).should == v }
end
it 'should work in special cases' do
{
'oauth' => "OAuth",
'openid' => 'OpenID',
'open_id' => 'OpenID'
}.each_pair{ |k,v| OmniAuth::Utils.camelize(k).should == v}
it 'should work in special cases that have been added' do
OmniAuth.config.add_camelization('oauth', 'OAuth')
OmniAuth::Utils.camelize(:oauth).should == 'OAuth'
end
end
end