class PackerFiles::Debian::Preseed
Public Class Methods
new(filename)
click to toggle source
Constructor. The preseed file name is the name of the file that will be written to.
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 13 def initialize(filename) @preseed = filename create_file end
Public Instance Methods
convert(obj, os_name)
click to toggle source
Serializes the given object and write out the content in the output file.
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 20 def convert(obj, os_name) file = erb_file(obj, os_name) content = PackerFiles.evaluate_erb(file, { "obj" => obj }) add_content(content) end
eval_file(file_name, hash)
click to toggle source
Evaluate a partially specified file name (should be in the Gem's file list though) and add the content to the @preseed file
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 28 def eval_file(file_name, hash) erb_file = PackerFiles.DirPath(file_name).first content = PackerFiles.evaluate_erb(erb_file, hash) add_content(content) end
Private Instance Methods
add_content(content)
click to toggle source
Add content to the preseed file
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 58 def add_content(content) File.open(@preseed, 'a') {|f| f.write(content) } end
create_file()
click to toggle source
Create a new file with no content
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 50 def create_file basename = File.dirname(@preseed) FileUtils.mkdir_p(basename) if !Dir.exist?(basename) File.open(@preseed, 'w') {|f| f.write ''} end
erb_file(obj, os_name)
click to toggle source
Given an object, figure out the class name and return back the correct erb file name.
# File lib/PackerFiles/OS/Debian/Preseed.rb, line 37 def erb_file(obj, os_name) erb_file = File.join(os_name, obj.class.name.gsub(/.*::/,'') + '_erb.rb') erb_path = PackerFiles.DirPath(erb_file) if erb_path.nil? || erb_path.empty? raise RuntimeError.new("Template Path #{erb_file} does not exist") end return erb_path.first end