Class: StackTracer

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

Instance Method Summary collapse

Constructor Details

#initialize(base_path) ⇒ StackTracer

Returns a new instance of StackTracer.



11
12
13
14
# File 'lib/stack_tracer.rb', line 11

def initialize(base_path)
  @git_client = GitClient.new({"git_dir" => File.join(base_path, ".git")})
  @cache = ProjectCache.new(base_path)
end

Instance Method Details

#trace(error_id, deployed_commit_id = nil, last_deployed_commit_id = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stack_tracer.rb', line 16

def trace(error_id, deployed_commit_id=nil, last_deployed_commit_id=nil)
  error = @cache.read("errors")[error_id.to_s].deep_symbolize_keys
  commits = @cache.read("commits")
  deploys = @cache.read("deploys")

  deployed_commits = deploys
    .map { |deploy| commits[deploy["revision"]] }
    .reject(&:nil?)
    .sort_by { |commit| commit["date"] }

  deployed_commit_id ||= after_deployed_commit(error[:first_time], deployed_commits)
  last_deployed_commit_id ||= prior_deployed_commit(error[:first_time], deployed_commits)

  git_files = git_files(deployed_commit_id.to_s)
  stacktrace = stacktrace(error, git_files)
  trace_files = trace_files(stacktrace, git_files)
  trace_lines = trace_lines(stacktrace, trace_files, commits, last_deployed_commit_id.to_s)

  detail(error, trace_lines)
end