Skip to content

Instantly share code, notes, and snippets.

/dm-core.rb Secret

Created January 10, 2009 12:43
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 anonymous/2a2db4f125e911d23492 to your computer and use it in GitHub Desktop.
Save anonymous/2a2db4f125e911d23492 to your computer and use it in GitHub Desktop.
def self.setup(name, uri_or_options)
assert_kind_of 'name', name, Symbol
assert_kind_of 'uri_or_options', uri_or_options, Addressable::URI, Hash, String
case uri_or_options
when Hash
adapter_name = uri_or_options[:adapter].to_s
when String, DataObjects::URI, Addressable::URI
uri_or_options = Addressable::URI.parse(uri_or_options) if uri_or_options.kind_of?(String)
adapter_name = uri_or_options.scheme
end
class_name = Extlib::Inflection.classify(adapter_name) + 'Adapter'
unless Adapters::const_defined?(class_name)
lib_name = "#{Extlib::Inflection.underscore(adapter_name)}_adapter"
begin
adapter_file = root / 'lib' / 'dm-core' / 'adapters' / lib_name
require adapter_file
rescue LoadError => e
begin
require lib_name
rescue Exception
# library not found, raise the original error
raise e
end
end
end
Repository.adapters[name] = Adapters::const_get(class_name).new(name, uri_or_options)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment