Class: Build::Files::Directory

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

Constant Summary

Constants inherited from List

List::NONE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

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

Constructor Details

#initialize(root) ⇒ Directory

Returns a new instance of Directory.



30
31
32
# File 'lib/build/files/directory.rb', line 30

def initialize(root)
  @root = root
end

Class Method Details

.join(*args) ⇒ Object



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

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

Instance Method Details

#eachObject



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

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

Returns:

  • (Boolean)


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

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

#hashObject



55
56
57
# File 'lib/build/files/directory.rb', line 55

def hash
  @root.hash
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#rebase(root) ⇒ Object



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

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

#rootObject



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

def root
  @root
end

#rootsObject



38
39
40
# File 'lib/build/files/directory.rb', line 38

def roots
  [root]
end

#to_pathObject



77
78
79
# File 'lib/build/files/directory.rb', line 77

def to_path
  @root
end

#to_sObject



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

def to_s
  to_str
end

#to_strObject

Convert a Directory into a String, can be used as an argument to a command.



69
70
71
# File 'lib/build/files/directory.rb', line 69

def to_str
  @root.to_str
end