- Notifications
You must be signed in to change notification settings - Fork810
Description
elasticsearch-model only loads the corresponding extensions if thekaminari orwill_paginate has already been loaded when it is loaded.
| case | |
| whendefined?(::Kaminari) | |
| Elasticsearch::Model::Response::Response.__send__:include,Elasticsearch::Model::Response::Pagination::Kaminari | |
| whendefined?(::WillPaginate) | |
| Elasticsearch::Model::Response::Response.__send__:include,Elasticsearch::Model::Response::Pagination::WillPaginate | |
| end |
In a typical Rails application, gems are usually loaded withBundler.require in config/application.rb, which means that unless those gems are listed in the Gemfile beforeelasticsearch-model, it won’t work as intended.
The fact that behavior changes depending on the order of gems makes it very confusing and prone to misunderstandings. I think it would be much better to improve it by using mechanisms likeActiveSupport.on_load hooks so that it no longer depends on the load order.
For example, theBundler/OrderedGems rule from rubocop-rails, commonly used in Rails development, enforces sorting gems alphabetically in the Gemfile. Following this,elasticsearch-model would appear beforekaminari orwill_paginate, making this issue a frequent occurrence.