Class: Overcommit::StagedFile
- Inherits:
-
Object
- Object
- Overcommit::StagedFile
- Defined in:
- lib/overcommit/staged_file.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#original_path ⇒ Object
readonly
Returns the value of attribute original_path.
Instance Method Summary collapse
-
#filter_string(string) ⇒ Object
Given error output from a syntax checker, replace references to the temporary file path with the original path.
-
#initialize(path) ⇒ StagedFile
constructor
A new instance of StagedFile.
-
#modified_lines ⇒ Object
Returns the set of line numbers corresponding to the lines that were changed in this file.
-
#path ⇒ Object
The path of the temporary file on disk, suitable for feeding in to a syntax checker.
Constructor Details
#initialize(path) ⇒ StagedFile
Returns a new instance of StagedFile.
11 12 13 14 |
# File 'lib/overcommit/staged_file.rb', line 11 def initialize(path) @original_path = path @contents = `git show :#{@original_path}` end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
9 10 11 |
# File 'lib/overcommit/staged_file.rb', line 9 def contents @contents end |
#original_path ⇒ Object (readonly)
Returns the value of attribute original_path.
9 10 11 |
# File 'lib/overcommit/staged_file.rb', line 9 def original_path @original_path 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.
18 19 20 |
# File 'lib/overcommit/staged_file.rb', line 18 def filter_string(string) string.gsub(path, @original_path) end |
#modified_lines ⇒ Object
Returns the set of line numbers corresponding to the lines that were changed in this file.
39 40 41 |
# File 'lib/overcommit/staged_file.rb', line 39 def modified_lines @modified_lines ||= extract_modified_lines end |
#path ⇒ Object
The path of the temporary file on disk, suitable for feeding in to a syntax checker.
24 25 26 |
# File 'lib/overcommit/staged_file.rb', line 24 def path tempfile.path end |