Class: Teapot::Build::FileList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/teapot/build/file_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, pattern, prefix = nil) ⇒ FileList

Returns a new instance of FileList.



33
34
35
36
37
# File 'lib/teapot/build/file_list.rb', line 33

def initialize(root, pattern, prefix = nil)
	@root = root
	@pattern = pattern
	@prefix = Pathname.new(prefix || ".")
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



40
41
42
# File 'lib/teapot/build/file_list.rb', line 40

def pattern
  @pattern
end

#prefixObject (readonly)

Returns the value of attribute prefix.



41
42
43
# File 'lib/teapot/build/file_list.rb', line 41

def prefix
  @prefix
end

#rootObject (readonly)

Returns the value of attribute root.



39
40
41
# File 'lib/teapot/build/file_list.rb', line 39

def root
  @root
end

Class Method Details

.[](root, pattern, prefix = nil) ⇒ Object



29
30
31
# File 'lib/teapot/build/file_list.rb', line 29

def self.[] (root, pattern, prefix = nil)
	self.new(root, pattern, prefix)
end

Instance Method Details

#copy(destination) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/teapot/build/file_list.rb', line 47

def copy(destination)
	self.each do |path|
		# Compute the destination path, which is formed using the relative path:
		relative_path = path.relative_path_from(@root)
		destination_path = destination + @prefix + relative_path
		
		if path.directory?
			# Make a directory at the destination:
			destination_path.mkpath
		else
			# Make the path if it doesn't already exist:
			destination_path.dirname.mkpath
		
			# Copy the file to the destination:
			FileUtils.cp(path, destination_path, :preserve => true)
		end
	end
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/teapot/build/file_list.rb', line 43

def each(&block)
	Pathname.glob(@root + @pattern).each &block
end