Class: Overcommit::StagedFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ StagedFile

Returns a new instance of StagedFile.



11
12
13
14
15
# File 'lib/overcommit/staged_file.rb', line 11

def initialize(path)
  @original_path  = path
  @tempfile       = Tempfile.new([path.gsub('/', '_'), File.extname(path)])
  self.contents   = `git show :#{@original_path}`
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



9
10
11
# File 'lib/overcommit/staged_file.rb', line 9

def contents
  @contents
end

Instance Method Details

#filter_string(string) ⇒ Object

Given error output from a syntax checker, replace references to the temporary file path with the original path.



19
20
21
# File 'lib/overcommit/staged_file.rb', line 19

def filter_string(string)
  string.gsub(path, @original_path)
end

#modified_linesObject

Returns the set of line numbers corresponding to the lines that were changed in this file.



42
43
44
# File 'lib/overcommit/staged_file.rb', line 42

def modified_lines
  @modified_lines ||= extract_modified_lines
end

#pathObject

The path of the temporary file on disk, suitable for feeding in to a syntax checker.



25
26
27
# File 'lib/overcommit/staged_file.rb', line 25

def path
  @tempfile.path
end