class Cangallo::Cangafile
Constants
- ACTIONS
Attributes
data[RW]
Public Class Methods
new(file)
click to toggle source
# File lib/cangallo/cangafile.rb, line 81 def initialize(file) text = File.read(file) @data = YAML.load(text) @params = [] @head = [] @tail = [] if !@data["tasks"] || @data["tasks"].class != Array raise "No tasks defined or it's not an array" end @tasks = @data["tasks"] end
Public Instance Methods
add_head(str)
click to toggle source
# File lib/cangallo/cangafile.rb, line 129 def add_head(str) @head << str end
add_parameter(str)
click to toggle source
# File lib/cangallo/cangafile.rb, line 137 def add_parameter(str) @params << str end
add_tail(str)
click to toggle source
# File lib/cangallo/cangafile.rb, line 133 def add_tail(str) @tail.unshift(str) end
file_commands()
click to toggle source
# File lib/cangallo/cangafile.rb, line 141 def file_commands text = "" if @data["files"] @data["files"].each do |line| l = line.gsub(" ", ":") text << "copy-in #{l}\n" end end return text end
libguestfs_commands()
click to toggle source
# File lib/cangallo/cangafile.rb, line 166 def libguestfs_commands @tasks.each do |task| if task.class != Hash raise "This task is not a hash: #{task}" end end end
libguestfs_commands_old()
click to toggle source
# File lib/cangallo/cangafile.rb, line 176 def libguestfs_commands_old text = file_commands text << run_commands text end
parent()
click to toggle source
# File lib/cangallo/cangafile.rb, line 182 def parent @data["parent"] end
render()
click to toggle source
# File lib/cangallo/cangafile.rb, line 96 def render @tasks.each do |task| raise %Q{Task "#{task.inspect}" malformed} if task.class != Hash action_name = task.keys.first action_data = task[action_name] if !ACTIONS.keys.include?(action_name) raise %Q{Invalid action "#{action_name}"} end action = ACTIONS[action_name] if action["type"] type = [action["type"]].flatten else type = [String] end # Check action value type task_type = action_data.class if !type.include?(task_type) raise %Q{Action parameters for "#{action_name}" must be "#{type.inspect}"} end if action["action"] instance_exec(action_data, &action["action"]) end end return @head + @tail, @params end
run_commands()
click to toggle source
# File lib/cangallo/cangafile.rb, line 154 def run_commands text = "" if @data["run"] @data["run"].each do |line| text << "run-command #{line}\n" end end return text end