Skip to content

Instantly share code, notes, and snippets.

@sent-hil
Created January 22, 2012 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sent-hil/1656550 to your computer and use it in GitHub Desktop.
Save sent-hil/1656550 to your computer and use it in GitHub Desktop.
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'active_support/inflector'
module OpenAuth2
module Provider
class Base
attr_accessor :client_id
def initialize
@client_id = :default_client_id
super
end
def configure
yield self
self
end
def set_defaults
options.each do |key,value|
instance_variable_set("@#{key}", value)
end
end
end
class Default < Base
def options
{}
end
end
class Facebook < Base
def options
{}
end
end
end
class Config
Keys = [
:client_id,
]
attr_accessor *Keys, :provider
Keys.each do |key|
define_method key do
instance_variable_get("@#{key}") || @provider.send(key)
end
end
def initialize
set_default_as_provider
yield self if block_given?
self
end
def provider=(name)
@provider = name
const_provider.set_defaults
end
def configure
yield self
self
end
def reset_providers
set_default_as_provider
end
private
def set_default_as_provider
send(:provider=, :default)
end
def const_provider
provider = @provider.to_s.capitalize
string = ['OpenAuth2', 'Provider', provider].join('::')
@provider = string.constantize.new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment