diff --git a/app/models/miq_report/seeding.rb b/app/models/miq_report/seeding.rb index 114ffb43c7d4..b39d0cd7024e 100644 --- a/app/models/miq_report/seeding.rb +++ b/app/models/miq_report/seeding.rb @@ -1,8 +1,10 @@ module MiqReport::Seeding extend ActiveSupport::Concern - REPORT_DIR = Rails.root.join("product/reports") - COMPARE_DIR = Rails.root.join("product/compare") + RELATIVE_REPORT_DIR = "product/reports".freeze + RELATIVE_COMPARE_DIR = "product/compare".freeze + REPORT_DIR = Rails.root.join(RELATIVE_REPORT_DIR).freeze + COMPARE_DIR = Rails.root.join(RELATIVE_COMPARE_DIR).freeze module ClassMethods def seed @@ -66,7 +68,7 @@ def seed_record(path, report) attrs[:priority] = File.basename(path).split("_").first.to_i attrs[:rpt_group] = File.basename(File.dirname(path)).split("_").last attrs[:rpt_type] = "Default" - attrs[:template_type] = path.start_with?(REPORT_DIR.to_s) ? "report" : "compare" + attrs[:template_type] = template_type(path) begin report.update!(attrs) @@ -84,12 +86,34 @@ def seed_record(path, report) end end + def template_type(path) + path.include?(RELATIVE_REPORT_DIR.to_s) ? "report" : "compare" + end + def seed_files + seed_core_files + seed_plugin_files + end + + def seed_core_files Dir.glob(REPORT_DIR.join("**/*.yaml")).sort + Dir.glob(COMPARE_DIR.join("**/*.yaml")).sort end + def seed_plugin_files + Vmdb::Plugins.flat_map do |plugin| + Dir.glob(plugin.root.join("#{RELATIVE_REPORT_DIR}/**/*.yaml")).sort + Dir.glob(plugin.root.join("#{RELATIVE_COMPARE_DIR}/**/*.yaml")).sort + end + end + def seed_filename(path) - path.remove("#{REPORT_DIR}/").remove("#{COMPARE_DIR}/") + send("seed_#{template_type(path)}", path) + end + + def seed_report_filename(path) + path.split("#{RELATIVE_REPORT_DIR}/").last + end + + def seed_compare_filename(path) + path.split("#{RELATIVE_COMPARE_DIR}/").last end end end