Class: Build::Graph::CallStack

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

Overview

A call stack contains frames to track state during nested invocations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallStack

Returns a new instance of CallStack.



25
26
27
28
# File 'lib/build/graph/call_stack.rb', line 25

def initialize
	# Saves state if supplied to #call, which is useful for top level state:
	@frames = [{}.freeze]
end

Instance Attribute Details

#framesObject (readonly)

All stack frames which had state associated with them.



31
32
33
# File 'lib/build/graph/call_stack.rb', line 31

def frames
  @frames
end

Instance Method Details

#lastObject

The current stack frame state.



45
46
47
# File 'lib/build/graph/call_stack.rb', line 45

def last
	@frames.last
end

#with(state) ⇒ Object

Yield with the given state, merged with any prior state.



34
35
36
37
38
39
40
41
42
# File 'lib/build/graph/call_stack.rb', line 34

def with(state)
	if state and !state.empty?
		@frames << @frames.last.merge(state).freeze
		yield
		@frames.pop
	else
		yield
	end
end