Skip to content

Instantly share code, notes, and snippets.

@timogoebel
Last active April 23, 2018 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timogoebel/17f29624d7117b951d7778b6bcd58dfb to your computer and use it in GitHub Desktop.
Save timogoebel/17f29624d7117b951d7778b6bcd58dfb to your computer and use it in GitHub Desktop.
# lib/foreman_solarwinds/engine.rb
config.autoload_paths += Dir["#{config.root}/app/services"]
config.autoload_paths += Dir["#{config.root}/app/services/concerns"]
config.to_prepare do
begin
::IPAM.send(:include, ForemanSolarwinds::IpamExtensions)
rescue StandardError => e
Rails.logger.warn "ForemanSolarwinds: skipping engine hook (#{e})"
end
end
# app/services/concerns/foreman_solarwinds/ipam_extensions.rb
module ForemanSolarwinds
module IpamExtensions
extend ActiveSupport::Concern
module Overrides
module ClassMethods
def new(type, *args)
if type == ::IPAM::MODES[:solarwinds]
::IPAM::Solarwinds.new(*args)
else
super
end
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
included do
::IPAM::MODES[:solarwinds] ||= N_('Solarwinds')
prepend Overrides
end
end
end
# app/services/ipam/solarwinds.rb
module IPAM
class Solarwinds < Base
def suggest_ip
# Your code here
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment