$:.unshift File.dirname(__FILE__) require 'cotta_file' module BuildMaster class CottaDir attr_reader :path, :system def initialize(system, path) @system = system @path = path @name = @path.basename.to_s end def cotta return Cotta.new(@system) end def name return @path.basename.to_s end def exists? return @system.dir_exists?(@path) end def parent if (@name == '.') return nil end return CottaDir.new(@system, @path.parent) end def dir(name) return CottaDir.new(@system, @path.join(name)) end def file(name) return CottaFile.new(@system, @path.join(name)) end def mkdirs if (not exists?) parent.mkdirs @system.mkdir @path end end def delete list.each {|children| children.delete} @system.delete_dir(@path) end def move_to(target) target.parent.mkdirs @system.move_dir(@path, target.path) end def copy_to(target) target.parent.mkdirs @system.copy_dir(@path, target.path) end def list @system.list(@path).collect do |item| candidate = dir(item) if (not candidate.exists?) candidate = file(item) end candidate end end def ==(other) return @path == other.path && @system == other.system end def to_s return "#{super}-#@system-#@path" end end end