Class: Bake::Base

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

Overview

The base class for including Scope instances which define Recipe instances.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



11
12
13
# File 'lib/bake/base.rb', line 11

def context
  @context
end

Class Method Details

.derive(path = []) ⇒ Object

Generate a base class for the specified path.



14
15
16
17
18
19
20
# File 'lib/bake/base.rb', line 14

def self.derive(path = [])
	klass = Class.new(self)
	
	klass.const_set(:PATH, path)
	
	return klass
end

.inspectObject



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

def self.inspect
	if path = self.path
		"Bake::Base<#{path.join(':')}>"
	else
		super
	end
end

.pathObject

The path of this derived base class.



42
43
44
45
46
# File 'lib/bake/base.rb', line 42

def self.path
	self.const_get(:PATH)
rescue
	nil
end

.to_sObject

Format the class as a command.



24
25
26
27
28
29
30
# File 'lib/bake/base.rb', line 24

def self.to_s
	if path = self.path
		path.join(':')
	else
		super
	end
end

Instance Method Details

#call(*arguments) ⇒ Object

Proxy a method call using command line arguments through to the Context instance.



56
57
58
# File 'lib/bake/base.rb', line 56

def call(*arguments)
	self.context.call(*arguments)
end

#pathObject

The path for this derived base class.



50
51
52
# File 'lib/bake/base.rb', line 50

def path
	self.class.path
end

#recipe_for(name) ⇒ Object

Look up a recipe with a specific name.



78
79
80
# File 'lib/bake/base.rb', line 78

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

#recipesObject

Recipes defined in this scope.



65
66
67
68
69
70
71
72
73
# File 'lib/bake/base.rb', line 65

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

#to_sObject



82
83
84
# File 'lib/bake/base.rb', line 82

def to_s
	"\#<#{self.class}>"
end