Class: PowerTrace::Entry

Inherits:
Object
  • Object
show all
Includes:
ColorizeHelper
Defined in:
lib/power_trace/entry.rb

Constant Summary collapse

UNDEFINED =
"[undefined]"
EMPTY_STRING =
""
EMPTY_ARRAY =
[].freeze
EMPTY_HASH =
{}.freeze
SET_IVAR_INSTRUCTION_REGEX =
/setinstancevariable/
SPACE =
"\s"
DEFAULT_LINE_LIMIT =
100
ATTRIBUTE_COLORS =
{
  name: :blue,
  location: :green,
  arguments_string: :orange,
  locals_string: :megenta,
  ivars_string: :cyan
}

Constants included from ColorizeHelper

ColorizeHelper::COLOR_CODES, ColorizeHelper::RESET_MARK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame) ⇒ Entry

Returns a new instance of Entry.



17
18
19
20
21
22
23
# File 'lib/power_trace/entry.rb', line 17

def initialize(frame)
  @frame = frame
  @filepath, @line_number = frame.source_location
  @receiver = frame.receiver
  @locals, @arguments = collect_locals_and_arguments
  @ivars = collect_ivars
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def arguments
  @arguments
end

#filepathObject (readonly)

Returns the value of attribute filepath.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def filepath
  @filepath
end

#frameObject (readonly)

Returns the value of attribute frame.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def frame
  @frame
end

#ivarsObject (readonly)

Returns the value of attribute ivars.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def ivars
  @ivars
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def line_number
  @line_number
end

#localsObject (readonly)

Returns the value of attribute locals.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def locals
  @locals
end

#receiverObject (readonly)

Returns the value of attribute receiver.



15
16
17
# File 'lib/power_trace/entry.rb', line 15

def receiver
  @receiver
end

Instance Method Details

#arguments_string(options = {}) ⇒ Object



33
34
35
36
37
38
# File 'lib/power_trace/entry.rb', line 33

def arguments_string(options = {})
  <<~STR.chomp
    #{options[:indentation]}(Arguments)
    #{hash_to_string(arguments, false, options)}
  STR
end

#call_trace(options = {}) ⇒ Object



54
55
56
# File 'lib/power_trace/entry.rb', line 54

def call_trace(options = {})
  "#{location(options)}:in `#{name(options)}'"
end

#ivars_string(options = {}) ⇒ Object



47
48
49
50
51
52
# File 'lib/power_trace/entry.rb', line 47

def ivars_string(options = {})
  <<~STR.chomp
    #{options[:indentation]}(Instance Variables)
    #{hash_to_string(ivars, false, options)}
  STR
end

#locals_string(options = {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/power_trace/entry.rb', line 40

def locals_string(options = {})
  <<~STR.chomp
    #{options[:indentation]}(Locals)
    #{hash_to_string(locals, false, options)}
  STR
end

#location(options = {}) ⇒ Object



29
30
31
# File 'lib/power_trace/entry.rb', line 29

def location(options = {})
  "#{filepath}:#{line_number}"
end

#name(options = {}) ⇒ Object



25
26
27
# File 'lib/power_trace/entry.rb', line 25

def name(options = {})
  frame.frame_description
end

#to_s(options = {}) ⇒ Object



81
82
83
84
85
# File 'lib/power_trace/entry.rb', line 81

def to_s(options = {})
  # this is to prevent entries from polluting each other's options
  # of course, that'd only happen if I did something stupid ;)
  assemble_string(options.dup)
end