mastodon.me.uk is one of the many independent Mastodon servers you can use to participate in the fediverse.
Open, user-supported, corporation-free social media for the UK.

Administered by:

Server stats:

503
active users

James Smith 💾

question: does anyone know if you can enable/disable (and even install?) Rails Engines at runtime, to behave as some sort of dynamic application extension plugin system? I'm wondering about having a way to enable optional features for @manyfold...

@floppy @manyfold the only real lever you have is ActionDispatch::Routing::Mapper::Base#mount, which is intended to be called on startup in routes.rb. You *could* call it later and mount other engines, I guess*, but there's no opposite #unmount.

*Would require some fiddling with ActionDispatch::Routing::RouteSet#draw via disable_clear_and_finalize because the default behaviour there is to clear routes when called.

In short, it's a voyage of discovery because there's no mechanism obvious to me.

@floppy @manyfold probably the best thing you could do would be to 404 in the engine itself when it's turned off?

@rgarner @manyfold yeah, not ideal really. Don’t mind an app restart, but loading them or not based on a setting seems tricky. Might need a custom approach.

@floppy @manyfold if you don't mind an app restart (and a fatuous example) then is

mount Sidekiq::Web, at: '/admin/sidekiq' if ENV['SIDEKIQ_ENABLED']

out of the question in routes.rb?

@floppy any mileage in abusing one or more `constraints` blocks with custom FeatureConstraints#matches?

@rgarner hm, maybe…. This is all useful stuff thank you. Helpful to have ideas just bouncing around ❤️

@rgarner I’m trying to think how to make a system like plugins.octoprint.org/; could be that engines aren’t quite the right thing, but maybe there’s a way I can bend them to my will.

OctoPrint Plugin RepositoryOctoPrint Plugin RepositoryThe official OctoPrint Plugin Repository

@floppy all an Engine really is is a Rack app (a Proc returning an array) that has a routing match associated with it at boot time via #mount (routes end up compiled so there's no real 'dynamic' there to speak of), so if your plugins map naturally to sprouting a bunch of new paths, so much the better – spike out something with constraints (no reboot required!)

If it's something different to that? Dunno. Couldn't divine the OctoPrint boundary from a cursory glance...

@floppy I suppose in your use case the only difference would be rather than mounting a fixed set, you'd need to iterate some form of manifest to mount

@rgarner very interesting, thank you! I’ve obviously nerd-sniped you very effectively with this question 😅

@floppy don't define constants in blocks, obvs. I've just formatted this so you can paste it directly into your routes and test-drive. Also the naming is pish