diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 67ba767dfbd..8e2f72a5204 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -11,8 +11,12 @@ def self.with_tenant(tenant_id) where(:tenant_id => tenant.ancestor_ids + [tenant_id]) end + def self.concrete_subclasses + leaf_subclasses | descendants.select { |d| d.try(:acts_as_sti_leaf_class?) } + end + def self.types - leaf_subclasses.collect(&:ems_type) + concrete_subclasses.collect(&:ems_type) end def self.supported_types @@ -20,7 +24,7 @@ def self.supported_types end def self.supported_subclasses - leaf_subclasses.select(&:permitted?) + concrete_subclasses.select(&:permitted?) end def self.permitted? @@ -405,7 +409,7 @@ def self.model_name_from_emstype(emstype) def self.model_from_emstype(emstype) emstype = emstype.downcase - ExtManagementSystem.leaf_subclasses.detect { |k| k.ems_type == emstype } + ExtManagementSystem.concrete_subclasses.detect { |k| k.ems_type == emstype } end def self.short_token diff --git a/app/models/miq_schedule_worker/runner.rb b/app/models/miq_schedule_worker/runner.rb index d479a96fc7a..ecf7ac7d971 100644 --- a/app/models/miq_schedule_worker/runner.rb +++ b/app/models/miq_schedule_worker/runner.rb @@ -504,7 +504,7 @@ def do_work # @returns Hash Hash of ems_class => refresh_interval def schedule_settings_for_ems_refresh - ExtManagementSystem.leaf_subclasses.each.with_object({}) do |klass, hash| + ExtManagementSystem.supported_subclasses.each.with_object({}) do |klass, hash| next unless klass.ems_type every = ::Settings.ems_refresh[klass.ems_type].try(:refresh_interval) || ::Settings.ems_refresh.refresh_interval every = every.respond_to?(:to_i_with_method) ? every.to_i_with_method : every.to_i diff --git a/app/models/provider.rb b/app/models/provider.rb index a753d433003..c3549afab27 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -25,14 +25,12 @@ class Provider < ApplicationRecord supports :refresh_ems - def self.leaf_subclasses - descendants.select { |d| d.subclasses.empty? } + def self.concrete_subclasses + leaf_subclasses | descendants.select { |d| d.try(:acts_as_sti_leaf_class?) } end def self.supported_subclasses - subclasses.flat_map do |s| - s.subclasses.empty? ? s : s.supported_subclasses - end + concrete_subclasses end def self.short_token diff --git a/lib/acts_as_sti_leaf_class.rb b/lib/acts_as_sti_leaf_class.rb new file mode 100644 index 00000000000..a1e00774ea2 --- /dev/null +++ b/lib/acts_as_sti_leaf_class.rb @@ -0,0 +1,14 @@ +module ActsAsStiLeafClass + extend ActiveSupport::Concern + + module ClassMethods + def acts_as_sti_leaf_class? + true + end + + private def type_condition(table = arel_table) + sti_column = table[inheritance_column] + predicate_builder.build(sti_column, [sti_name]) + end + end +end diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index a1beda76ce9..1cd040c8575 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -37,7 +37,7 @@ end it ".model_name_from_emstype" do - described_class.leaf_subclasses.each do |klass| + described_class.concrete_subclasses.each do |klass| expect(described_class.model_name_from_emstype(klass.ems_type)).to eq(klass.name) end expect(described_class.model_name_from_emstype('foo')).to be_nil