Own-and-Ship / oas_agent

The Own & Ship Ruby agent
2 stars 0 forks source link

Integrate into Rails through Railtie/initializers #42

Closed caius closed 8 months ago

caius commented 8 months ago

What?

Why?

Instead of trying to attach ourselves after the rails configuration has setup deprecation behaviour and take care of everything in every version of rails that reads that config setting, instead lets have our initialiser run just before Rails sets up deprecation behaviour in the app during startup so we get Rails to do the heavy lifting for us. Rails has allowed multiple behaviours to be set through this config variable since it was introduced in Rails 3.0.

This looks like a more "railsy" way to integrate, and has the nice advantage we don't need to track what Rails is doing, as long as it supports config.active_support.deprecation it'll do the right thing. The new deprecators collection in Rails 7.1+ still gets populated from this config option for example.

caius commented 8 months ago

Testing this in the main app locally. Changing config/environments/development.rb and then outputting stuff from Rails Runner. We're looking specifically at:

✅ With config.active_support.deprecation = :log we get [:log, our proc] returned in all three places.

✅ With # config.active_support.deprecation (ie, commented out), we get [our proc] returned from all three places.

✅ With config.active_support.deprecation = [:log, :notify] we get [:log, :notify, our proc] from all three places.

caius commented 8 months ago

Extracted the Railtie out to its own file to make it easier to add a test for it. Mocked rails out rather than try and pull a version of it in and deal with it.