lib/buildmaster/cotta/cotta_dir.rb in BuildMaster-0.9.1 vs lib/buildmaster/cotta/cotta_dir.rb in BuildMaster-1.0.6

- old
+ new

@@ -5,32 +5,41 @@ module BuildMaster class CottaDir attr_reader :path, :system def initialize(system, path) - @system = system @path = path + @system = system @name = @path.basename.to_s end def cotta return Cotta.new(@system) end def name - return @path.basename.to_s + 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 - if (@name == '.') - return nil - end - return CottaDir.new(@system, @path.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 @@ -54,15 +63,23 @@ 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) @@ -73,11 +90,15 @@ 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 - return "#{super}-#@system-#@path" + @path end end end \ No newline at end of file