This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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