class Workspace::Dir
Attributes
path[RW]
workspace[RW]
Public Class Methods
new(workspace, path = "/")
click to toggle source
# File lib/workspace/dir.rb, line 9 def initialize(workspace, path = "/") @workspace = workspace @path = path end
Public Instance Methods
==(other)
click to toggle source
# File lib/workspace/dir.rb, line 5 def ==(other) other.class == self.class && other.to_s == self.to_s end
absolute_path()
click to toggle source
# File lib/workspace/dir.rb, line 29 def absolute_path to_s end
children(glob = "*") { |entry| ... }
click to toggle source
# File lib/workspace/dir.rb, line 87 def children(glob = "*", &block) entries = [] ::Dir.chdir(to_s) do ::Dir[glob].each do |path| entry = ::File.directory?(::File.join(to_s, path)) ? dir(path) : file(path) yield entry if block_given? entries.push(entry) end end entries end
clean()
click to toggle source
# File lib/workspace/dir.rb, line 66 def clean delete create end
copy(target_dir)
click to toggle source
# File lib/workspace/dir.rb, line 50 def copy(target_dir) target_dir.parent_dir.create unless target_dir.parent_dir.exists? FileUtils.cp_r(to_s, target_dir.to_s) self end
create()
click to toggle source
# File lib/workspace/dir.rb, line 37 def create FileUtils.mkdir_p(to_s) self end
delete()
click to toggle source
# File lib/workspace/dir.rb, line 62 def delete FileUtils.rm_rf(to_s) end
dir(dir_path)
click to toggle source
# File lib/workspace/dir.rb, line 75 def dir(dir_path) Workspace::Dir.new(@workspace, ::File.join(@path, dir_path)) end
directories(&block)
click to toggle source
# File lib/workspace/dir.rb, line 103 def directories(&block) children("*/", &block) end
empty?()
click to toggle source
# File lib/workspace/dir.rb, line 46 def empty? !exists? or children.count == 0 end
exists?()
click to toggle source
# File lib/workspace/dir.rb, line 42 def exists? ::File.directory?(to_s) end
file(file_path)
click to toggle source
# File lib/workspace/dir.rb, line 71 def file(file_path) Workspace::File.new(@workspace, ::File.join(@path, file_path)) end
files(&block)
click to toggle source
# File lib/workspace/dir.rb, line 99 def files(&block) children("*.*", &block) end
move(target_dir)
click to toggle source
# File lib/workspace/dir.rb, line 56 def move(target_dir) target_dir.parent_dir.create unless target_dir.parent_dir.exists? FileUtils.mv(to_s, target_dir.to_s) self end
name()
click to toggle source
# File lib/workspace/dir.rb, line 33 def name ::File.basename(to_s) end
parent_dir()
click to toggle source
# File lib/workspace/dir.rb, line 83 def parent_dir root_dir.dir(::File.expand_path("..", @path)) end
relative_path(relative_dir = nil)
click to toggle source
# File lib/workspace/dir.rb, line 18 def relative_path(relative_dir = nil) if relative_dir relative_dir = relative_dir.dir if relative_dir.class == Workspace::File first = Pathname.new(relative_dir.path) second = Pathname.new(path) second.relative_path_from(first).to_s else @path.gsub(%r{^/}, "") end end
root_dir()
click to toggle source
# File lib/workspace/dir.rb, line 79 def root_dir Workspace::Dir.new(@workspace, "") end
to_s()
click to toggle source
# File lib/workspace/dir.rb, line 14 def to_s ::File.join(@workspace, @path) end