Class: Build::Graph::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/build/graph/controller.rb

Overview

The top level graph controller is responsible for managing build graph state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



32
33
34
35
36
37
38
# File 'lib/build/graph/controller.rb', line 32

def initialize
	super
	
	@nodes = {}
	
	build_graph!
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



40
41
42
# File 'lib/build/graph/controller.rb', line 40

def nodes
  @nodes
end

Instance Method Details

#build_graph!Object

Build the initial graph structure.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/build/graph/controller.rb', line 55

def build_graph!
	# We build the graph without doing any actual execution:
	nodes = []
	
	walker = walk do |walker, node|
		nodes << node
		
		yield walker, node
	end
	
	traverse! walker
	
	# We should update the status of all nodes in the graph once we've traversed the graph.
	nodes.each do |node|
		node.update_status!
	end
end

#task_failure(error, task) ⇒ Object

What to do when a task has a trasient failure:



102
103
104
# File 'lib/build/graph/controller.rb', line 102

def task_failure(error, task)
	$stderr.puts Rainbow("Error: #{error.inspect}").red
end

#traverse!(walker) ⇒ Object

Override this to traverse the top nodes as required.



43
44
45
46
47
# File 'lib/build/graph/controller.rb', line 43

def traverse!(walker)
	#Array(top).each do |node|
	#	node.update!(walker)
	#end
end

#update!Object

Update the graph.



91
92
93
94
95
96
97
98
99
# File 'lib/build/graph/controller.rb', line 91

def update!
	walker = walk do |walker, node|
		yield walker, node
	end
	
	traverse! walker
	
	return walker
end

#update_with_logObject

Update the graph and print out timing information.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/build/graph/controller.rb', line 74

def update_with_log
	puts Rainbow("*** Graph update traversal ***").green
	
	start_time = Time.now
	
	walker = update!
	
	return walker
ensure
	end_time = Time.now
	elapsed_time = end_time - start_time

	$stdout.flush
	$stderr.puts Rainbow("Graph Update Time: %0.3fs" % elapsed_time).magenta
end

#walk(&block) ⇒ Object

Walk the graph with the given callback.



50
51
52
# File 'lib/build/graph/controller.rb', line 50

def walk(&block)
	Walker.new(self, &block)
end