Skip to content

Commit bbcae43

Browse files
Merge pull request #164 from Navdevl/fix-unneeded-migration-creation
Handling the unneeded migration filecreation using method_added capture approach
2 parents 2872dc3 + 2e30901 commit bbcae43

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/activeadmin-mongoid.rb

+28
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
require 'active_admin/mongoid'
2+
require "rails/generators/actions"
3+
require "rails/generators/named_base"
4+
5+
# Considering the Rails::Generators::NamedBase is one of the nearest ancestor to
6+
# ActiveAdmin::Generators::InstallGenerator, we can open the class and an empty create_migration
7+
# to the class(which will overridden by other subclasses). We can specifically focus on the
8+
# ActiveAdmin::Generators::InstallGenerator class and apply remove_method during the method_added call
9+
# and thereby pushing ActiveAdmin::Generators::InstallGenerator to use our empty create_migrations method.
10+
11+
Rails::Generators::NamedBase.class_eval do
12+
13+
def create_migrations
14+
end
15+
16+
def self.inherited(klass)
17+
super
18+
if klass.name == "ActiveAdmin::Generators::InstallGenerator"
19+
20+
klass.class_eval do
21+
def self.method_added(method_name)
22+
super
23+
remove_method method_name if method_name == :create_migrations
24+
end
25+
end
26+
end
27+
end
28+
end
29+

0 commit comments

Comments
 (0)