Class: Build::Files::Difference

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

Overview

Represents a list of files with exclusions applied.

Constant Summary

Constants inherited from List

List::NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from List

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

Constructor Details

#initialize(list, excludes) ⇒ Difference

Initialize a difference list.



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

def initialize(list, excludes)
	@list = list
	@excludes = excludes
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



20
21
22
# File 'lib/build/files/difference.rb', line 20

def files
  @files
end

Instance Method Details

#-(list) ⇒ Object

Subtract additional files from this difference.



44
45
46
# File 'lib/build/files/difference.rb', line 44

def -(list)
	self.class.new(@list, Composite.new([@excludes, list]))
end

#eachObject

Iterate over files in the base list, excluding those in the exclusion list.



33
34
35
36
37
38
39
# File 'lib/build/files/difference.rb', line 33

def each
	return to_enum(:each) unless block_given?
	
	@list.each do |path|
		yield path unless @excludes.include?(path)
	end
end

#freezeObject

Freeze the difference list and its dependencies.



23
24
25
26
27
28
# File 'lib/build/files/difference.rb', line 23

def freeze
	@list.freeze
	@excludes.freeze
	
	super
end

#include?(path) ⇒ Boolean

Check if the difference includes a specific path.

Returns:

  • (Boolean)


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

def include?(path)
	@list.include?(path) and !@excludes.include?(path)
end

#inspectObject

Generate a string representation for debugging.



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

def inspect
	"<Difference #{@list.inspect} - #{@excludes.inspect}>"
end

#rebase(root) ⇒ Object

Rebase the difference to a new root.



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

def rebase(root)
	self.class.new(@list.rebase(root), @excludes.rebase(root))
end