Class: Gloo::Exec::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/exec/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Stack

Set up the stack.



16
17
18
19
20
# File 'lib/gloo/exec/stack.rb', line 16

def initialize( name )
  @name = name
  clear_stack
  $log.debug "#{name} stack intialized..."
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



11
12
13
# File 'lib/gloo/exec/stack.rb', line 11

def stack
  @stack
end

Instance Method Details

#clear_stackObject

Clear the stack and the output file.



71
72
73
74
# File 'lib/gloo/exec/stack.rb', line 71

def clear_stack
  @stack = []
  self.update_out_file
end

#out_dataObject

Get stack data for output.



50
51
52
# File 'lib/gloo/exec/stack.rb', line 50

def out_data
  return @stack.map( &:display_value ).join( "\n" )
end

#out_fileObject

Get the file we’ll write debug information for the stack.



57
58
59
# File 'lib/gloo/exec/stack.rb', line 57

def out_file
  return File.join( $settings.debug_path, @name )
end

#popObject

Pop an item from the stack.



34
35
36
37
38
# File 'lib/gloo/exec/stack.rb', line 34

def pop
  o = @stack.pop
  $log.debug "#{@name}:pop #{o.display_value}"
  self.update_out_file if $settings.debug
end

#push(obj) ⇒ Object

Push an item onto the stack.



25
26
27
28
29
# File 'lib/gloo/exec/stack.rb', line 25

def push( obj )
  $log.debug "#{@name}:push #{obj.display_value}"
  @stack.push obj
  self.update_out_file if $settings.debug
end

#sizeObject

Get the current size of the call stack.



43
44
45
# File 'lib/gloo/exec/stack.rb', line 43

def size
  return @stack.size
end

#update_out_fileObject

Update the stack trace file.



64
65
66
# File 'lib/gloo/exec/stack.rb', line 64

def update_out_file
  File.write( self.out_file, self.out_data )
end