Class: Bake::Registry::Aggregate

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAggregate

Initialize an empty array of registry.



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

def initialize
	# Used to de-duplicated directories:
	@roots = {}
	
	# The ordered list of loaders:
	@ordered = Array.new
end

Class Method Details

.default(working_directory, bakefile_path = nil) ⇒ Object

Create a loader using the specified working directory.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bake/registry/aggregate.rb', line 19

def self.default(working_directory, bakefile_path = nil)
	registry = self.new
	
	if bakefile_path
		registry.append_bakefile(bakefile_path)
	end
	
	registry.append_defaults(working_directory)
	
	return registry
end

Instance Method Details

#append_bakefile(path) ⇒ Object



57
58
59
# File 'lib/bake/registry/aggregate.rb', line 57

def append_bakefile(path)
	@ordered << BakefileLoader.new(path)
end

#append_defaults(working_directory) ⇒ Object

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



76
77
78
79
80
81
82
# File 'lib/bake/registry/aggregate.rb', line 76

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.



85
86
87
88
89
90
91
92
93
# File 'lib/bake/registry/aggregate.rb', line 85

def append_from_gems
	::Gem.loaded_specs.each do |name, spec|
		Console.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_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.



64
65
66
67
68
69
70
71
72
# File 'lib/bake/registry/aggregate.rb', line 64

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 registry in order.



47
48
49
# File 'lib/bake/registry/aggregate.rb', line 47

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

#empty?Boolean

Whether any registry are defined.

Returns:

  • (Boolean)


42
43
44
# File 'lib/bake/registry/aggregate.rb', line 42

def empty?
	@ordered.empty?
end

#scopes_for(path, &block) ⇒ Object



51
52
53
54
55
# File 'lib/bake/registry/aggregate.rb', line 51

def scopes_for(path, &block)
	@ordered.each do |registry|
		registry.scopes_for(path, &block)
	end
end