From 3408033f71f9cd641c37a91d345db5ce834ebd03 Mon Sep 17 00:00:00 2001 From: Pablo Ruiz <439480+guapolo@users.noreply.github.com> Date: Sat, 12 Dec 2020 01:44:51 -0600 Subject: [PATCH] Rails 6.1 support --- lib/rails_erd/domain.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rails_erd/domain.rb b/lib/rails_erd/domain.rb index f292409b..b7b88831 100644 --- a/lib/rails_erd/domain.rb +++ b/lib/rails_erd/domain.rb @@ -49,7 +49,13 @@ def initialize(models = [], options = {}) # Returns the domain model name, which is the name of your Rails # application or +nil+ outside of Rails. def name - defined? Rails and Rails.application and Rails.application.class.parent.name + if defined? Rails && Rails.application + if rails_6_1_or_above? + Rails.application.class.module_parent_name + else + Rails.application.class.parent.name + end + end end # Returns all entities of your domain model. @@ -167,5 +173,9 @@ def association_description(association) def check_habtm_model(model) model.name.start_with?("HABTM_") end + + def rails_6_1_or_above? + (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 6 + end end end