Class: GitHooks::PreCommit::TrailingWhitespace
- Inherits:
-
Object
- Object
- GitHooks::PreCommit::TrailingWhitespace
- Defined in:
- lib/git_hooks/pre_commit/trailing_whitespace.rb
Instance Attribute Summary collapse
-
#git_repository ⇒ Object
readonly
Returns the value of attribute git_repository.
-
#trailing_whitespace_validator ⇒ Object
readonly
Returns the value of attribute trailing_whitespace_validator.
Class Method Summary collapse
Instance Method Summary collapse
- #changed_files ⇒ Object
-
#initialize(git_repository, trailing_whitespace_validator) ⇒ TrailingWhitespace
constructor
A new instance of TrailingWhitespace.
- #offenses ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(git_repository, trailing_whitespace_validator) ⇒ TrailingWhitespace
Returns a new instance of TrailingWhitespace.
13 14 15 16 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 13 def initialize(git_repository, trailing_whitespace_validator) @git_repository = git_repository @trailing_whitespace_validator = trailing_whitespace_validator end |
Instance Attribute Details
#git_repository ⇒ Object (readonly)
Returns the value of attribute git_repository.
4 5 6 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 4 def git_repository @git_repository end |
#trailing_whitespace_validator ⇒ Object (readonly)
Returns the value of attribute trailing_whitespace_validator.
4 5 6 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 4 def trailing_whitespace_validator @trailing_whitespace_validator end |
Class Method Details
.validate ⇒ Object
6 7 8 9 10 11 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 6 def self.validate new( GitHooks.configurations.git_repository, TrailingWhitespaceValidator.new ).validate end |
Instance Method Details
#changed_files ⇒ Object
24 25 26 27 28 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 24 def changed_files git_repository .added_or_modified .select { |file| File.extname(file) == '.rb' } end |
#offenses ⇒ Object
30 31 32 33 34 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 30 def offenses changed_files.map do |file| trailing_whitespace_validator.errors?([file]) end end |
#validate ⇒ Object
18 19 20 21 22 |
# File 'lib/git_hooks/pre_commit/trailing_whitespace.rb', line 18 def validate abort( "Prevented commit with trailing whitespace in files #{offenses}" ) if offenses.any? end |