> Thanks for the input on trying a plugin. I have successfully figured out
> how to add the new field to the db and create it under the Media field
> (edit host, OS). I am having issues however overwriting the methods in the
> models/operatingsystems class. As per the example I have created a
> models/host_extensions.rb with the following contents
>
> module AddBuildId
> module HostExtensions
> extend ActiveSupport::Concern
> module ClassMethods
> def medium_uri(host, url = nil)
> url ||= host.medium.path
> medium_vars_to_uri(url, host.architecture.name,
> host.operatingsystem, host.buildid)
> end
> def medium_vars_to_uri(url, arch, os, buildid)
> URI.parse(interpolate_medium_vars(url, arch, os, buildid)).normalize
> end
> def interpolate_medium_vars(path, arch, os, buildid)
> return "" if path.empty?
> path.gsub('$arch', arch).
> gsub('$major', os.major).
> gsub('$minor', os.minor).
> gsub('$version', os.minor.blank? ? os.major : [os.major,
> os.minor].compact.join('.')).
> gsub('$release', os.release_name.blank? ? '' :
> os.release_name).
> gsub('$buildid', buildid)
> end
> end
> end
> end
Hi,
Glad you got the plugin going.
Part of the problem is these aren't class methods, but rather instance methods.
I would reccomend alias_method_chain[1] to extend medium_uri itself, instead of
trying to get down into the interpolate_medium_vars method.
Something like this should do:
module AddBuildId
module HostExtensions
extend ActiveSupport::Concern
included do
alias_method_chain :medium_uri, :build_id
end
def medium_uri_with_build_id(host, url = nil)
medium_uri_without_build_id(host, url).gsub('$buildid', host.buildid)
end
end
end
[1] http://apidock.com/rails/v3.2.8/Module/alias_method_chain
···
On Fri, Aug 21, 2015 at 02:51:35PM -0700, Ryan Dyer wrote:
And within the engine.rb loading it via:
config.to_prepare do
begin
Operatingsystem.send(:include, AddBuildId::HostExtensions)
but it is not doing what I want still. Any suggestions would be greatly
appreciated.
Thanks,
Ryan
–
You received this message because you are subscribed to the Google Groups “foreman-dev” group.
To unsubscribe from this group and stop receiving emails from it, send an email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
–
Best Regards,
Stephen Benjamin
Red Hat Engineering