Class: Airbrake::CodeHunk Private

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/airbrake-ruby/code_hunk.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a small hunk of code consisting of a base line and a couple lines around it

Constant Summary collapse

MAX_LINE_LEN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns the maximum length of a line.

Returns:

  • (Integer)

    the maximum length of a line

200
NLINES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns how many lines should be read around the base line.

Returns:

  • (Integer)

    how many lines should be read around the base line

2

Instance Method Summary collapse

Methods included from Loggable

#logger

Instance Method Details

#get(file, line) ⇒ Hash{Integer=>String}?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns lines of code around the base line.

Parameters:

  • file (String)

    The file to read

  • line (Integer)

    The base line in the file

Returns:

  • (Hash{Integer=>String}, nil)

    lines of code around the base line



17
18
19
20
21
22
23
24
25
# File 'lib/airbrake-ruby/code_hunk.rb', line 17

def get(file, line)
  return unless File.exist?(file)
  return unless line

  lines = get_lines(file, [line - NLINES, 1].max, line + NLINES) || {}
  return { 1 => '' } if lines.empty?

  lines
end