Skip to content

Commit

Permalink
Camelizations are now added through OmniAuth.config
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Sep 22, 2011
1 parent 69177f3 commit 98bc2b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
28 changes: 8 additions & 20 deletions lib/omniauth.rb
Expand Up @@ -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']
Expand All @@ -31,9 +32,7 @@ class Configuration
:default => {
'provider' => 'default',
'uid' => '1234',
'user_info' => {
'name' => 'Bob Example'
}
'name' => 'Bob Example'
}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }
Expand Down
11 changes: 4 additions & 7 deletions spec/omniauth/core_spec.rb → spec/omniauth_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path('../../spec_helper', __FILE__)
require 'spec_helper'

describe OmniAuth do
describe '.strategies' do
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 98bc2b9

Please sign in to comment.