local-ch / lhs

⚛️ REST services accelerator: Rails gem providing an easy, active-record-like interface for http (hypermedia) json services
GNU General Public License v3.0
137 stars 3 forks source link

Preload "provider inheriting" records, too #378

Closed 10xSebastian closed 4 years ago

10xSebastian commented 4 years ago

With the growing usage of providers – which reduces endpoint options/configuration redundancy (especially authorization) – the following problem popped up:

LHS needs to preload LHS record classes stored in your application (usually within models/) to know all existing endpoints at all time. LHS needs to know all existing endpoints at all time because it needs to infer from a url like http://storage/places/1 to the corresponding class e.g. Place to apply endpoint configurations (like authorization).

The previous auto-loading algorithm was implemented before providers and wasn't loading LHS records which where inheriting from provider classes.

This improves the autoloader to ensure classes inheriting from providers also get preloaded from LHS.

LHS test setup also had to be improved slightly:

dimameshcharakou commented 4 years ago

One note, which might be related to this (maybe not, though): when i recently setup rails 6 app, then i'm constantly getting the deprecation warning when rails is being initialized: Rails.application.initialize!

DEPRECATION WARNING: Initialization autoloaded the constants LocalEntry, Chat, and Message.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload LocalEntry, for example,
the expected changes won't be reflected in that stale Class object.

These autoloaded constants have been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.

And LocalEntry, Chat, and Message are inherited from LHS::Record But i suppose it'd be better to just provide the complete test app in such case.