From 511429b6f3be59488e4961e0be4daaf88b1e0777 Mon Sep 17 00:00:00 2001
From: "Yuya.Nishida" <yuya@j96.org>
Date: Sun, 11 Jun 2023 17:09:09 +0900
Subject: [PATCH 2/2] refactor: to more simply code

---
 config/routes.rb | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/config/routes.rb b/config/routes.rb
index 3bc012a3e..6176fdfae 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -404,15 +404,11 @@
 
   get 'robots', :to => 'welcome#robots'
 
-  Dir.glob(File.expand_path("#{Redmine::Plugin.directory}/*")).sort.each do |plugin_dir|
-    file = File.join(plugin_dir, "config/routes.rb")
-    if File.exist?(file)
-      begin
-        instance_eval File.read(file)
-      rescue SyntaxError, StandardError => e
-        puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}."
-        exit 1
-      end
-    end
+  Redmine::Plugin.directory.glob("*/config/routes.rb").sort.each do |plugin_routes_path|
+    instance_eval(plugin_routes_path.read, plugin_routes_path.to_s)
+  rescue SyntaxError, StandardError => e
+    plugin_name = plugin_routes_path.parent.parent.basename.to_s
+    puts "An error occurred while loading the routes definition of #{plugin_name} plugin (#{plugin_routes_path}): #{e.message}."
+    exit 1
   end
 end
-- 
2.25.1

