class Build::Files::List

A list of paths, where #each yields instances of Path.

def self.coerce(arg)

@returns [List] A list instance.
@parameter arg [List | Object] The object to coerce.
Coerce an argument to a List instance.
def self.coerce(arg)
	if arg.kind_of? self
		arg
	else
		Paths.new(arg)
	end
end

def +(list)

Create a composite list out of two other lists:
def +(list)
	Composite.new([self, list])
end

def -(list)

@returns [Difference] A difference list excluding the given paths.
@parameter list [List] The list to subtract.
Subtract a list from this list.
def -(list)
	Difference.new(self, list)
end

def ==(other)

This isn't very efficient, but it IS generic.
def ==(other)
	if self.class == other.class
		self.eql?(other)
	elsif other.kind_of? self.class
		self.to_a.sort == other.to_a.sort
	else
		super
	end
end

def copy(destination)

@parameter destination [Path] The destination root path.
Copy all files in the list to a destination.
def copy(destination)
	each do |path|
		path.copy(destination / path.relative_path)
	end
end

def create

Recursively create paths for all listed paths.
def create
	each(&:create)
end

def delete

Recursively delete all paths and all contents within those paths.
def delete
	each(&:delete)
end

def empty?

@returns [Boolean] True if the list contains no paths.
Check if the list is empty.
def empty?
	each do
		return false
	end
	
	return true
end

def exist?

Check that all files listed exist.
def exist?
	all?(&:exist?)
end

def intersects? other

Does this list of files include the path of any other?
def intersects? other
	other.any?{|path| include?(path)}
end

def map

@returns [Paths] A new paths list with mapped values.
@parameter path [Path] The current path.
@yields {|path| ...} Each path in the list.
Map over the list and return a Paths instance.
def map
	Paths.new(super)
end

def rebase(root)

@returns [Paths] A new paths list with rebased paths.
@parameter root [Path] The new root path.
Rebase all paths in the list to a new root.
def rebase(root)
	Paths.new(self.collect{|path| path.rebase(root)}, [root])
end

def roots

@returns [Array(Path)] Sorted unique root paths.
Get all unique root paths from the list.
def roots
	collect{|path| path.root}.sort.uniq
end

def to_paths

@returns [Paths] A paths list containing all items.
Convert the list to a Paths instance.
def to_paths
	Paths.new(each.to_a)
end

def to_s

@returns [String] The string representation.
Convert the list to a string.
def to_s
	inspect
end

def touch

Touch all listed files.
def touch
	each(&:touch)
end

def with(**options)

@returns [Paths] A new paths list with transformed paths.
@parameter updated_path [Path] The modified path.
@parameter path [Path] The original path.
@yields {|path, updated_path| ...} Each original and updated path.
@parameter options [Hash] Options to pass to {Path#with}.
Transform paths with modified attributes.
def with(**options)
	return to_enum(:with, **options) unless block_given?
	
	paths = []
	
	self.each do |path|
		updated_path = path.with(**options)
		
		yield path, updated_path
		
		paths << updated_path
	end
	
	return Paths.new(paths)
end