Skip to content

Commit

Permalink
Deal with Nic model by explicit preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jun 28, 2024
1 parent de2e48f commit c4554d4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
4 changes: 0 additions & 4 deletions app/models/concerns/foreman/sti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module Foreman
module STI
extend ActiveSupport::Concern

prepended do
cattr_accessor :preloaded, instance_accessor: false
end

class_methods do
# ensures that the correct STI object is created when :type is passed.
def new(attributes = nil, &block)
Expand Down
2 changes: 0 additions & 2 deletions app/models/nic/bmc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,4 @@ def validate_bmc_proxy
errors.add(:type, e.message)
end
end

Base.register_type(BMC)
end
2 changes: 0 additions & 2 deletions app/models/nic/bond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ def self.humanized_name
N_('Bond')
end
end

Base.register_type(Bond)
end
2 changes: 0 additions & 2 deletions app/models/nic/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ def self.humanized_name
N_('Bridge')
end
end

Base.register_type(Bridge)
end
2 changes: 0 additions & 2 deletions app/models/nic/managed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,4 @@ def setup_clone
@old
end
end

Base.register_type(Managed)
end
7 changes: 0 additions & 7 deletions config/initializers/6_preload_stis.rb

This file was deleted.

11 changes: 11 additions & 0 deletions config/initializers/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@

ReportImporter.register_smart_proxy_feature("Puppet")
end

# Preload here all classes which use Foreman::STI and using registration methods
# E.g. Base.register_type(BMC)
# Some constants that use such classes may be defined before all the related classes/models are loaded and registered
# E.g. InterfaceTypeMapper::ALLOWED_TYPE_NAMES
Rails.application.reloader.to_prepare do
Nic::Base.register_type(Nic::Managed)
Nic::Base.register_type(Nic::BMC)
Nic::Base.register_type(Nic::Bond)
Nic::Base.register_type(Nic::Bridge)
end

0 comments on commit c4554d4

Please sign in to comment.