Class: Teapot::Graph

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

Defined Under Namespace

Classes: Extractor, Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



26
27
28
29
30
# File 'lib/teapot/graph.rb', line 26

def initialize
	@nodes = {}
	
	@extractors = []
end

Instance Attribute Details

#extractorsObject (readonly)

Returns the value of attribute extractors.



34
35
36
# File 'lib/teapot/graph.rb', line 34

def extractors
  @extractors
end

#nodesObject (readonly)

Returns the value of attribute nodes.



33
34
35
# File 'lib/teapot/graph.rb', line 33

def nodes
  @nodes
end

#rootObject (readonly)

Returns the value of attribute root.



32
33
34
# File 'lib/teapot/graph.rb', line 32

def root
  @root
end

Instance Method Details

#<<(node) ⇒ Object



36
37
38
# File 'lib/teapot/graph.rb', line 36

def << node
	@nodes[node.path] = node
end

#extract(source_path) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/teapot/graph.rb', line 54

def extract(source_path)
	dependencies = Set.new

	@extractors.each do |extractor|
		extractor.call(source_path) do |path|
			dependencies << path
		end
	end

	nodes = dependencies.map{|path| fetch(path)}
end

#fetch(path) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/teapot/graph.rb', line 66

def fetch(path)
	@nodes.fetch(path) do
		node = @nodes[path] = Node.new(self, path)
		node.extract_dependencies!
		
		node
	end
end

#regenerate?(output_path, input_paths) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/teapot/graph.rb', line 40

def regenerate?(output_path, input_paths)
	return true unless output_path.exist?

	output_modified_time = output_path.mtime

	Array(input_paths).each do |path|
		node = fetch(path)

		return true if node.changed_since?(output_modified_time)
	end

	return false
end