Class: Errordeck::Stacktrace

Inherits:
Object
  • Object
show all
Defined in:
lib/errordeck/errordeck/issue/stacktrace.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root, line) ⇒ Stacktrace

Returns a new instance of Stacktrace.



10
11
12
13
14
15
16
17
18
19
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 10

def initialize(project_root, line)
  @abs_path = line.file
  @function = line.method
  @in_app = line.file.start_with?(project_root)
  @filename = File.basename(line.file)
  @lineno = line.line
  @module = line.module_name
  @vars = {}
  set_contexts(line.file, line.line)
end

Instance Attribute Details

#abs_pathObject

Returns the value of attribute abs_path.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def abs_path
  @abs_path
end

#context_lineObject

Returns the value of attribute context_line.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def context_line
  @context_line
end

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def filename
  @filename
end

#functionObject

Returns the value of attribute function.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def function
  @function
end

#in_appObject

Returns the value of attribute in_app.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def in_app
  @in_app
end

#linenoObject

Returns the value of attribute lineno.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def lineno
  @lineno
end

#moduleObject

Returns the value of attribute module.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def module
  @module
end

#post_contextObject

Returns the value of attribute post_context.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def post_context
  @post_context
end

#pre_contextObject

Returns the value of attribute pre_context.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def pre_context
  @pre_context
end

#varsObject

Returns the value of attribute vars.



7
8
9
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 7

def vars
  @vars
end

Class Method Details

.parse_from_backtrace(backtrace, project_root = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 40

def self.parse_from_backtrace(backtrace, project_root = nil)
  project_root ||= File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
  error_backtrace = Errordeck::Backtrace.parse(backtrace)
  return nil if error_backtrace.nil?

  error_backtrace.lines.map { |line| new(project_root, line) }
end

Instance Method Details

#as_json(*_options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 21

def as_json(*_options)
  {
    abs_path: @abs_path,
    function: @function,
    in_app: @in_app,
    filename: @filename,
    lineno: @lineno,
    module: @module,
    vars: @vars,
    context_line: @context_line,
    pre_context: @pre_context,
    post_context: @post_context
  }
end

#to_json(*options) ⇒ Object



36
37
38
# File 'lib/errordeck/errordeck/issue/stacktrace.rb', line 36

def to_json(*options)
  JSON.generate(as_json, *options)
end