Class: Build::Files::Directory

Inherits:
List
  • Object
show all
Defined in:
lib/build/files/directory.rb

Overview

Represents a directory of files.

Constant Summary

Constants inherited from List

List::NONE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

#+, #-, #==, coerce, #copy, #create, #delete, #empty?, #exist?, #intersects?, #map, #to_paths, #touch, #with

Constructor Details

#initialize(root) ⇒ Directory

Initialize a directory with a root path.



21
22
23
# File 'lib/build/files/directory.rb', line 21

def initialize(root)
	@root = root
end

Class Method Details

.join(*args) ⇒ Object

Join path components and create a directory.



15
16
17
# File 'lib/build/files/directory.rb', line 15

def self.join(*args)
	self.new(Path.join(*args))
end

Instance Method Details

#eachObject

Iterate over all files in the directory recursively.



40
41
42
43
44
45
46
47
# File 'lib/build/files/directory.rb', line 40

def each
	return to_enum(:each) unless block_given?
	
	# We match both normal files with * and dotfiles with .?*
	Dir.glob(@root + "**/{*,.?*}") do |path|
		yield Path.new(path, @root)
	end
end

#eql?(other) ⇒ Boolean

Check equality with another directory.

Returns:

  • (Boolean)


52
53
54
# File 'lib/build/files/directory.rb', line 52

def eql?(other)
	self.class.eql?(other.class) and @root.eql?(other.root)
end

#hashObject

Compute the hash value for this directory.



58
59
60
# File 'lib/build/files/directory.rb', line 58

def hash
	@root.hash
end

#include?(path) ⇒ Boolean

Check if the directory includes a specific path.

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/build/files/directory.rb', line 65

def include?(path)
	# Would be true if path is a descendant of full_path.
	path.start_with?(@root)
end

#rebase(root) ⇒ Object

Rebase the directory to a new root.



73
74
75
# File 'lib/build/files/directory.rb', line 73

def rebase(root)
	self.class.new(@root.rebase(root))
end

#rootObject

Get the root path of the directory.



27
28
29
# File 'lib/build/files/directory.rb', line 27

def root
	@root
end

#rootsObject

Get the root paths as an array.



33
34
35
# File 'lib/build/files/directory.rb', line 33

def roots
	[root]
end

#to_pathObject

Convert the directory to a path object.



91
92
93
# File 'lib/build/files/directory.rb', line 91

def to_path
	@root
end

#to_sObject

Convert the directory to a string.



85
86
87
# File 'lib/build/files/directory.rb', line 85

def to_s
	to_str
end

#to_strObject

Convert the directory to a string for use as a command argument.



79
80
81
# File 'lib/build/files/directory.rb', line 79

def to_str
	@root.to_str
end