Skip to content

Instantly share code, notes, and snippets.

/dm-core.rb Secret

Created Jan 10, 2009
Embed
What would you like to do?
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