foreman-export-god/lib/foreman/export/god.rb

47 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2012-02-02 01:23:23 +00:00
require 'foreman/export'
require 'foreman/cli'
class Foreman::Export::God < Foreman::Export::Base
def export
error("Must specify a location") unless location
FileUtils.mkdir_p location
app = self.app || File.basename(engine.directory)
2012-03-01 04:01:44 +00:00
base_template = export_template("god", "base.god.erb", template_root)
2012-02-02 01:23:23 +00:00
base_config = ERB.new(base_template).result(binding)
write_file(File.join(location, "#{app}.god"), base_config)
end
def extension(process_name)
if extensions.has_key?(process_name)
ERB.new(extension_template(process_name)).result(binding)
else
""
end
end
private
2012-03-01 04:01:44 +00:00
def template_root
template_root = self.template || File.expand_path("../../../../data/templates", __FILE__)
2012-02-02 01:23:23 +00:00
end
def extension_template(name)
IO.read(extensions[name])
end
def extensions
@extensions = load_extensions
end
def load_extensions
h = {}
2012-03-01 04:01:44 +00:00
Dir.glob(File.join(template_root, 'extensions',"*.erb")).each do |extension_path|
2012-02-02 01:23:23 +00:00
extension_name = extension_path.split("/").last.match(/(.*?).god.erb$/)[1]
h[extension_name] = extension_path
end
h
end
end