I’m developing a plugin Foreman v3.5.1 (starting with Foreman Plugin Template) and face the issue that one of my modules (DnsInterfaceExtensions
) does not properly overlay the methods of DnsInterface
.
While the foreman-rake console
does show my module as ancestor and source location of the methods as my Ruby code…
irb(main):001:0> DnsInterface.ancestors
=> [ForemanCnames::DnsInterfaceExtensions, DnsInterface]
irb(main):002:0> DnsInterface.instance_method(:dns_feasible?).source_location
=> ["/usr/local/share/gems/gems/foreman_cnames-0.0.1/app/models/foreman_cnames/dns_interface_extensions.rb", 13]
… I find that actually Foreman keeps using it own original method:
[root@satellite-test-01 foreman]# grep ORIGINAL app/models/concerns/dns_interface.rb
Foreman::Logging.logger('foreman_cnames').debug "ORIGINAL #{__method__} called"
[root@satellite-test-01 foreman]# egrep 'ed1bd4ac.*dns_feasible\?' /var/log/foreman/production.log
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
2024-07-29T11:05:03 [D|for|ed1bd4ac] ORIGINAL dns_feasible? called
Should I rather add our override to Nic::Managed
?
irb(main):001:0> Nic::Managed.ancestors.filter { |c| c.name =~ /Dns/ }
=> [DnsInterface]
irb(main):002:0> Nic::Managed.ancestors.filter { |c| c.name =~ /Cnames/ }
=> [ForemanCnames::Concerns::NicExtensions] # <<< different prepended module!
irb(main):003:0> Nic::Managed.instance_method(:dns_feasible?).source_location
=> ["/usr/share/foreman/app/models/concerns/dns_interface.rb", 22]