lundi 17 janvier 2022

Rails 3 initializing custom Railtie

In a Rails 3 project, I'm creating a custom Railtie in order to monkey patch the Rails migration generator. I'm using the multiverse gem as a source of inspiration as it's very close to what I'm trying to do, only in a higher version of Rails.

Here is my Railtie:

require "rails/railtie"


module MultiDb
  class Railtie < Rails::Railtie
    config.after_initialize do
      puts "Hello!"
    end

    generators do
      ActiveSupport.on_load(:active_record) do
        require "rails/generators/migration"
        Rails::Generators::Migration.prepend(MultiDb::MigrationTemplate)
      end
    end
  end
end

module MultiDb
  module MigrationTemplate
    def migration_template(source, destination, config = {})
      p "migration template"

      super
    end
  end
end

I'm just not sure how I'm supposed to actually load/register (not sure of the terminology here) when my application boots. I've tried adding an initializer that requires this file, but that hasn't done anything at all.

Aucun commentaire:

Enregistrer un commentaire