Class: Utils::LineBlamer

Inherits:
Object show all
Defined in:
lib/utils/line_blamer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, lineno = 1) ⇒ LineBlamer

Returns a new instance of LineBlamer.


3
4
5
# File 'lib/utils/line_blamer.rb', line 3

def initialize(file, lineno = 1)
  @file, @lineno = file, lineno
end

Class Method Details

.blame(line) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/utils/line_blamer.rb', line 11

def self.blame(line)
  blamer = for_line(line)
  if blame = blamer.perform
    blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
    blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
  end
end

.for_line(line) ⇒ Object


7
8
9
# File 'lib/utils/line_blamer.rb', line 7

def self.for_line(line)
  location = line.source_location and new *location
end

Instance Method Details

#perform(options = '') ⇒ Object


19
20
21
# File 'lib/utils/line_blamer.rb', line 19

def perform(options = '')
  `git 2>/dev/null blame #{options} -L #@lineno,+1 "#@file"`.full?
end