Class: Bake::Loaders

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bake/loaders.rb

Overview

Structured access to the working directory and loaded gems for loading bakefiles.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoaders

Initialize an empty array of loaders.



41
42
43
44
# File 'lib/bake/loaders.rb', line 41

def initialize
	@roots = {}
	@ordered = Array.new
end

Class Method Details

.default(working_directory) ⇒ Object

Create a loader using the specified working directory.

Parameters:

  • working_directory (String)


32
33
34
35
36
37
38
# File 'lib/bake/loaders.rb', line 32

def self.default(working_directory)
	loaders = self.new
	
	loaders.append_defaults(working_directory)
	
	return loaders
end

Instance Method Details

#append_defaults(working_directory) ⇒ Object

Add loaders according to the current working directory and loaded gems.

Parameters:

  • working_directory (String)


54
55
56
57
58
59
60
# File 'lib/bake/loaders.rb', line 54

def append_defaults(working_directory)
	# Load recipes from working directory:
	self.append_path(working_directory)
	
	# Load recipes from loaded gems:
	self.append_from_gems
end

#append_from_gemsObject

Enumerate all loaded gems and add them.



97
98
99
100
101
102
103
104
105
# File 'lib/bake/loaders.rb', line 97

def append_from_gems
	Gem.loaded_specs.each do |name, spec|
		Console.logger.debug(self) {"Checking gem #{name}: #{spec.full_gem_path}..."}
		
		if path = spec.full_gem_path and File.directory?(path)
			append_path(path, name: spec.full_name)
		end
	end
end

#append_from_root(current = Dir.pwd, **options) ⇒ Object

Search from the current working directory until a suitable bakefile is found and add it.

Parameters:

  • current (String) (defaults to: Dir.pwd)

    The path to start searching from.



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/bake/loaders.rb', line 82

def append_from_root(current = Dir.pwd, **options)
	while current
		append_path(current, **options)
		
		parent = File.dirname(current)
		
		if current == parent
			break
		else
			current = parent
		end
	end
end

#append_path(current = Dir.pwd, **options) ⇒ Object

Append a specific project path to the search path for recipes. The computed path will have ‘bake` appended to it.

Parameters:

  • current (String) (defaults to: Dir.pwd)

    The path to add.



70
71
72
73
74
75
76
77
78
# File 'lib/bake/loaders.rb', line 70

def append_path(current = Dir.pwd, **options)
	bake_path = File.join(current, "bake")
	
	if File.directory?(bake_path)
		return insert(bake_path, **options)
	end
	
	return false
end

#each(&block) ⇒ Object

Enumerate the loaders in order.



63
64
65
# File 'lib/bake/loaders.rb', line 63

def each(&block)
	@ordered.each(&block)
end

#empty?Boolean

Whether any loaders are defined.

Returns:

  • (Boolean)


48
49
50
# File 'lib/bake/loaders.rb', line 48

def empty?
	@ordered.empty?
end