Class: Build::Graph::CallStack
- Inherits:
-
Object
- Object
- Build::Graph::CallStack
- Defined in:
- lib/build/graph/call_stack.rb
Overview
A call stack contains frames to track state during nested invocations.
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
All stack frames which had state associated with them.
Instance Method Summary collapse
-
#initialize ⇒ CallStack
constructor
A new instance of CallStack.
-
#last ⇒ Object
The current stack frame state.
-
#with(state) ⇒ Object
Yield with the given state, merged with any prior state.
Constructor Details
#initialize ⇒ CallStack
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
#frames ⇒ Object (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
#last ⇒ Object
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 |