Class: State

Inherits:
Object
  • Object
show all
Defined in:
lib/debugtrace/state.rb

Overview

Have the trace state for a thread

Author:

  • Masato Kokubo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread_id) ⇒ State

Returns a new instance of State.



12
13
14
15
# File 'lib/debugtrace/state.rb', line 12

def initialize(thread_id)
  @thread_id = thread_id
  reset()
end

Instance Attribute Details

#nest_levelObject (readonly)

Returns the value of attribute nest_level.



9
10
11
# File 'lib/debugtrace/state.rb', line 9

def nest_level
  @nest_level
end

#previous_nest_levelObject (readonly)

Returns the value of attribute previous_nest_level.



10
11
12
# File 'lib/debugtrace/state.rb', line 10

def previous_nest_level
  @previous_nest_level
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



8
9
10
# File 'lib/debugtrace/state.rb', line 8

def thread_id
  @thread_id
end

Instance Method Details

#down_nestObject

Downs the nest level.

Returns:

  • Time: The time when the corresponding upNest method was invoked



39
40
41
42
43
# File 'lib/debugtrace/state.rb', line 39

def down_nest
    @previous_nest_level = @nest_level
    @nest_level -= 1
    return @times.length > 0 ? @times.pop() : Time.now
end

#resetObject



17
18
19
20
21
# File 'lib/debugtrace/state.rb', line 17

def reset
  @nest_level = 0
  @previous_nest_level = 0
  @times = []
end

#to_sObject



23
24
25
# File 'lib/debugtrace/state.rb', line 23

def to_s()
    return "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, times: #{@times}}"
end

#up_nestObject

Ups the nest level.



28
29
30
31
32
33
34
35
# File 'lib/debugtrace/state.rb', line 28

def up_nest
    @previous_nest_level = @nest_level
    if (@nest_level >= 0)
        @times.push(Time.now)
    end
    @nest_level += 1
    return nil
end