-
-
Save anonymous/2a2db4f125e911d23492 to your computer and use it in GitHub Desktop.
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
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