Class: Bake::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, name: nil) ⇒ Loader

Returns a new instance of Loader.



25
26
27
28
# File 'lib/bake/loader.rb', line 25

def initialize(root, name: nil)
	@root = root
	@name = name
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



34
35
36
# File 'lib/bake/loader.rb', line 34

def root
  @root
end

Instance Method Details

#eachObject



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

def each
	return to_enum unless block_given?
	
	Dir.glob("**/*.rb", base: @root) do |file_path|
		yield file_path.sub(/\.rb$/, '').split(File::SEPARATOR)
	end
end

#recipe_for(path) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bake/loader.rb', line 44

def recipe_for(path)
	if book = lookup(path)
		return book.lookup(path.last)
	else
		*path, name = *path
		
		if book = lookup(path)
			return book.lookup(name)
		end
	end
end

#scope_for(path) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/bake/loader.rb', line 56

def scope_for(path)
	*directory, file = *path
	
	file_path = File.join(@root, directory, "#{file}.rb")
	
	if File.exist?(file_path)
		return Scope.load(file_path, path)
	end
end

#to_sObject



30
31
32
# File 'lib/bake/loader.rb', line 30

def to_s
	"#{self.class} #{@name || @root}"
end