From 2e30901455c6bcc23b7cfe51ef589233ad85c1e1 Mon Sep 17 00:00:00 2001 From: Naveen Honest Raj K Date: Wed, 16 Jun 2021 06:11:06 -0700 Subject: [PATCH] Handling the unneeded migration filecreation using method_added capture approach Signed-off-by: Naveen Honest Raj K --- lib/activeadmin-mongoid.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/activeadmin-mongoid.rb b/lib/activeadmin-mongoid.rb index d9f077b..57ddd40 100644 --- a/lib/activeadmin-mongoid.rb +++ b/lib/activeadmin-mongoid.rb @@ -1 +1,29 @@ require 'active_admin/mongoid' +require "rails/generators/actions" +require "rails/generators/named_base" + +# Considering the Rails::Generators::NamedBase is one of the nearest ancestor to +# ActiveAdmin::Generators::InstallGenerator, we can open the class and an empty create_migration +# to the class(which will overridden by other subclasses). We can specifically focus on the +# ActiveAdmin::Generators::InstallGenerator class and apply remove_method during the method_added call +# and thereby pushing ActiveAdmin::Generators::InstallGenerator to use our empty create_migrations method. + +Rails::Generators::NamedBase.class_eval do + + def create_migrations + end + + def self.inherited(klass) + super + if klass.name == "ActiveAdmin::Generators::InstallGenerator" + + klass.class_eval do + def self.method_added(method_name) + super + remove_method method_name if method_name == :create_migrations + end + end + end + end +end +