$:.unshift File.dirname(__FILE__) require 'cotta_file' module BuildMaster class CottaDir attr_reader :path, :system def initialize(system, path) @path = path @system = system @name = @path.basename.to_s end def cotta return Cotta.new(@system) end def name name = nil if root? name = path.to_s else name = @path.basename.to_s end return name end def root? parent.nil? end def exists? return @system.dir_exists?(@path) end def parent parent_path = @path.cotta_parent return nil unless parent_path return CottaDir.new(@system, parent_path) 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 move_to_path(target_path) move_to(cotta.dir(target_path)) end def copy_to(target) target.parent.mkdirs @system.copy_dir(@path, target.path) end def copy_to_path(target_path) copy_to(cotta.dir(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 inspect return "#{self.class}:#{self.object_id}-#{@system.inspect}-#@path" end def to_s @path end end end