diff --git a/lib/omniauth.rb b/lib/omniauth.rb index 5a2201a98..3e8699a96 100644 --- a/lib/omniauth.rb +++ b/lib/omniauth.rb @@ -18,6 +18,7 @@ class Configuration include Singleton @@defaults = { + :camelizations => {}, :path_prefix => '/auth', :on_failure => Proc.new do |env| message_key = env['omniauth.error.type'] @@ -31,9 +32,7 @@ class Configuration :default => { 'provider' => 'default', 'uid' => '1234', - 'user_info' => { - 'name' => 'Bob Example' - } + 'name' => 'Bob Example' } } } @@ -75,8 +74,12 @@ def add_mock(provider, mock={}) 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 @@ def self.mock_auth_for(provider) 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 @@ def deep_merge(hash, other_hash) 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 } diff --git a/spec/omniauth/core_spec.rb b/spec/omniauth_spec.rb similarity index 87% rename from spec/omniauth/core_spec.rb rename to spec/omniauth_spec.rb index dffa5ce99..99e814bf9 100644 --- a/spec/omniauth/core_spec.rb +++ b/spec/omniauth_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../spec_helper', __FILE__) +require 'spec_helper' describe OmniAuth do describe '.strategies' do @@ -67,12 +67,9 @@ }.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