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 Method Summary collapse

Constructor Details

#initialize(thread_id) ⇒ State

Returns a new instance of State.



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

def initialize(thread_id)
  @thread_id = Common::check_type('thread_id', thread_id, Integer)
  reset()
end

Instance Method Details

#down_nestObject

Downs the nest level.

Returns:

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



61
62
63
64
65
# File 'lib/debugtrace/state.rb', line 61

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

#nest_levelObject

Returns the nest level.

Returns:

  • the nest level.



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

def nest_level
  @nest_level
end

#previous_line_countObject

Returns the previous line count.

Returns:

  • the previous line count.



29
30
31
# File 'lib/debugtrace/state.rb', line 29

def previous_line_count
  @previous_line_count
end

#previous_line_count=(value) ⇒ Object

Sets the previous line count.

Parameters:

  • value

    the previous line count



35
36
37
# File 'lib/debugtrace/state.rb', line 35

def previous_line_count=(value)
  @previous_line_count = Common::check_type('value', value, Integer)
end

#previous_nest_levelObject

Returns the previous nest level.

Returns:

  • the previous nest level.



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

def previous_nest_level
  @previous_nest_level
end

#resetObject



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

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

#thread_idObject

Returns the thread id.

Returns:

  • the thread id.



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

def thread_id
  @thread_id
end

#to_sObject



46
47
48
# File 'lib/debugtrace/state.rb', line 46

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

#up_nestObject

Ups the nest level.



51
52
53
54
55
56
57
# File 'lib/debugtrace/state.rb', line 51

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