Class: Workspace::WorkspaceDir

Inherits:
Object
  • Object
show all
Includes:
Archive
Defined in:
lib/workspace/workspace_dir.rb,
lib/workspace/workspace_dir/archive.rb

Defined Under Namespace

Modules: Archive

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Archive

#compress_zip

Constructor Details

#initialize(workspace, path = "") ⇒ WorkspaceDir



8
9
10
11
# File 'lib/workspace/workspace_dir.rb', line 8

def initialize(workspace, path = "")
  @workspace = workspace
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/workspace/workspace_dir.rb', line 6

def path
  @path
end

#workspaceObject

Returns the value of attribute workspace.



6
7
8
# File 'lib/workspace/workspace_dir.rb', line 6

def workspace
  @workspace
end

Instance Method Details

#absolute_pathObject



94
95
96
# File 'lib/workspace/workspace_dir.rb', line 94

def absolute_path
  File.absolute_path(to_s)
end

#chdir(target_dir = nil) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/workspace/workspace_dir.rb', line 56

def chdir(target_dir = nil)
  if target_dir.nil?
    self.class.new(to_s, "")
  else
    self.class.new(dir(target_dir).to_s, "")
  end
end

#childrenObject



68
69
70
71
72
73
74
75
76
# File 'lib/workspace/workspace_dir.rb', line 68

def children
  entries = []
  Dir.chdir(to_s) do
    Dir["*"].each do |path|
      entries.push(dir(path))
    end
  end
  entries
end

#copy(target_dir) ⇒ Object



30
31
32
33
# File 'lib/workspace/workspace_dir.rb', line 30

def copy(target_dir)
  target_dir.parent_dir.create unless target_dir.parent_dir.exists?
  FileUtils.cp_r(to_s, target_dir.to_s)
end

#createObject



21
22
23
24
# File 'lib/workspace/workspace_dir.rb', line 21

def create
  FileUtils.mkdir_p(to_s)
  self
end

#delete!Object



35
36
37
# File 'lib/workspace/workspace_dir.rb', line 35

def delete!
  FileUtils.rm_rf(to_s)
end

#dir(dir_path) ⇒ Object



48
49
50
# File 'lib/workspace/workspace_dir.rb', line 48

def dir(dir_path)
  self.class.new(@workspace, File.join(@path, dir_path))
end

#each_dir(&block) ⇒ Object



88
89
90
91
92
# File 'lib/workspace/workspace_dir.rb', line 88

def each_dir(&block)
  children.each do |subdir|
    yield(subdir)
  end
end

#exists?Boolean



26
27
28
# File 'lib/workspace/workspace_dir.rb', line 26

def exists?
  File.directory?(to_s)
end

#file(file_path) ⇒ Object



44
45
46
# File 'lib/workspace/workspace_dir.rb', line 44

def file(file_path)
  WorkspaceFile.new(@workspace, File.join(@path, file_path))
end

#files(glob = "*") ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/workspace/workspace_dir.rb', line 78

def files(glob = "*")
  entries = []
  Dir.chdir(to_s) do
    Dir[glob].each do |path|
      entries.push(file(path))
    end
  end
  entries
end

#nameObject



17
18
19
# File 'lib/workspace/workspace_dir.rb', line 17

def name
  File.basename(to_s)
end

#parent_dirObject



64
65
66
# File 'lib/workspace/workspace_dir.rb', line 64

def parent_dir
  root_dir.dir(File.expand_path("..", @path))
end

#reset!Object



39
40
41
42
# File 'lib/workspace/workspace_dir.rb', line 39

def reset!
  delete!
  create
end

#root_dirObject



52
53
54
# File 'lib/workspace/workspace_dir.rb', line 52

def root_dir
  self.class.new(@workspace, "")
end

#to_sObject



13
14
15
# File 'lib/workspace/workspace_dir.rb', line 13

def to_s
  File.join(@workspace, @path)
end