mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Better error message when requesting a driver that was not found. Fixes #21
This commit is contained in:
parent
0735870418
commit
56aa10c54d
2 changed files with 12 additions and 2 deletions
|
@ -81,4 +81,10 @@ describe DB do
|
||||||
db.scalar "bar"
|
db.scalar "bar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gives nice error message when no driver is registered for schema (#21)" do
|
||||||
|
expect_raises(ArgumentError, %(no driver was registered for the schema "foobar", did you maybe forget to require the database driver?)) do
|
||||||
|
DB.open "foobar://baz"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,14 +81,18 @@ module DB
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def self.driver_class(driver_name) : Driver.class
|
def self.driver_class(driver_name) : Driver.class
|
||||||
@@drivers.not_nil![driver_name]
|
drivers[driver_name]? ||
|
||||||
|
raise(ArgumentError.new(%(no driver was registered for the schema "#{driver_name}", did you maybe forget to require the database driver?)))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Registers a driver class for a given *driver_name*.
|
# Registers a driver class for a given *driver_name*.
|
||||||
# Should be called by drivers implementors only.
|
# Should be called by drivers implementors only.
|
||||||
def self.register_driver(driver_name, driver_class : Driver.class)
|
def self.register_driver(driver_name, driver_class : Driver.class)
|
||||||
|
drivers[driver_name] = driver_class
|
||||||
|
end
|
||||||
|
|
||||||
|
private def self.drivers
|
||||||
@@drivers ||= {} of String => Driver.class
|
@@drivers ||= {} of String => Driver.class
|
||||||
@@drivers.not_nil![driver_name] = driver_class
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Opens a database using the specified *uri*.
|
# Opens a database using the specified *uri*.
|
||||||
|
|
Loading…
Reference in a new issue