Module: Bake::Scope

Defined in:
lib/bake/scope.rb

Overview

Used for containing all methods defined in a bakefile.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(file_path, path = []) ⇒ Object

Load the specified file into a unique scope module, which can then be included into a Base instance.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bake/scope.rb', line 12

def self.load(file_path, path = [])
	scope = Module.new
	
	if scope.respond_to?(:set_temporary_name)
		scope.set_temporary_name("#{self.name}[#{file_path}]")
	end
	
	scope.extend(self)
	
	scope.const_set(:FILE_PATH, file_path)
	scope.const_set(:PATH, path)
	
	# yield scope if block_given?
	
	scope.module_eval(File.read(file_path), file_path)
	
	return scope
end

Instance Method Details

#file_pathObject

The path of the file that was used to load this scope.



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

def file_path
	pp file_path_self: self
	self.const_get(:FILE_PATH)
end

#pathObject

The path of the scope, relative to the root of the context.



53
54
55
# File 'lib/bake/scope.rb', line 53

def path
	self.const_get(:PATH)
end

#recipe_for(name) ⇒ Object

Look up a recipe with a specific name.



60
61
62
# File 'lib/bake/scope.rb', line 60

def recipe_for(name)
	Recipe.new(self, name, self.instance_method(name))
end

#recipesObject

Recipes defined in this scope.



36
37
38
39
40
41
42
43
44
# File 'lib/bake/scope.rb', line 36

def recipes
	return to_enum(:recipes) unless block_given?
	
	names = self.instance_methods
	
	names.each do |name|
		yield recipe_for(name)
	end
end