This change simply checks to see if the database-specific adapter is already loaded before it tries to require a file with an explicit path. With this change, projects that use geokit-rails can choose to provide their own adapters in initializers without causing unnecessary UnsupportedAdapter errors.
This simple change is the end of a very long story for my team. (Read on if you dare!) Our Rails app uses a custom database adapter to perform cryptographic functions (the excellent pgcrypto adapter by @flipsasser). For Geokit's purposes, the PGCrypto adapter can be treated identically to the PostgreSQL adapter. We had a lot of trouble getting geokit-rails to handle the situation correctly:
Out of the box, line 101 was raising an UnsupportedAdapter error. We knew that the code solution was as simple as class Geokit::Adapters::PGCrypto < Geokit::Adapters::PostgreSQL; end but the question was where to put that code.
First we tried placing a file in our own project at /lib/geokit-rails/adapters/pgcrypto.rb. That allowed geokit-rails to work, but only in lazy-loaded environments. In eager-loaded environments, Rails would find that file before geokit-rails did, and it would raise a NameError because it expects a class like Geokit::Adapters::PGCrypto to be found at the path /lib/geokit/adapters/pgcrypto.rb instead.
Next we tried placing the code at /lib/geokit/adapters/pgcrypto.rb, where Rails would expect it to be. This allows eager-loading to work, but geokit-rails would still trip and fall over anyway because the require on line 96 was explicitly looking for a file under geokit-rails/.
Trying to be clever, we placed a file at /lib/geokit-rails/adapters/pgcrypto.rb that simply loaded the file at /lib/geokit/adapters/pgcrypto.rb, but this suffered from the same problem where Rails would raise a NameError when trying to eager-load the file.
After tearing our hair out for a while, we decided that the best solution was to fork the gem and submit the PR you see here. We think this is a pretty common-sense solution that might benefit others without requiring any other changes.
This change simply checks to see if the database-specific adapter is already loaded before it tries to require a file with an explicit path. With this change, projects that use geokit-rails can choose to provide their own adapters in initializers without causing unnecessary UnsupportedAdapter errors.
This simple change is the end of a very long story for my team. (Read on if you dare!) Our Rails app uses a custom database adapter to perform cryptographic functions (the excellent pgcrypto adapter by @flipsasser). For Geokit's purposes, the PGCrypto adapter can be treated identically to the PostgreSQL adapter. We had a lot of trouble getting geokit-rails to handle the situation correctly:
class Geokit::Adapters::PGCrypto < Geokit::Adapters::PostgreSQL; end
but the question was where to put that code./lib/geokit-rails/adapters/pgcrypto.rb
. That allowed geokit-rails to work, but only in lazy-loaded environments. In eager-loaded environments, Rails would find that file before geokit-rails did, and it would raise a NameError because it expects a class likeGeokit::Adapters::PGCrypto
to be found at the path/lib/geokit/adapters/pgcrypto.rb
instead./lib/geokit/adapters/pgcrypto.rb
, where Rails would expect it to be. This allows eager-loading to work, but geokit-rails would still trip and fall over anyway because therequire
on line 96 was explicitly looking for a file undergeokit-rails/
./lib/geokit-rails/adapters/pgcrypto.rb
that simply loaded the file at/lib/geokit/adapters/pgcrypto.rb
, but this suffered from the same problem where Rails would raise a NameError when trying to eager-load the file.After tearing our hair out for a while, we decided that the best solution was to fork the gem and submit the PR you see here. We think this is a pretty common-sense solution that might benefit others without requiring any other changes.