class GitHooks::PreCommit::Rubocop
Constants
- RUBOCOP_STASH_NAME
Attributes
git[R]
options[R]
rubocop_validator[R]
Public Class Methods
new(git, rubocop_validator, options = {})
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 14 def initialize(git, rubocop_validator, options = {}) @git = git @rubocop_validator = rubocop_validator @options = options end
validate(options = {})
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 6 def self.validate(options = {}) new( GitHooks.configurations.git_repository, RubocopValidator.new, options ).validate end
Public Instance Methods
validate()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 20 def validate abort 'Check rubocop offences' if offences? end
Private Instance Methods
changed_files()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 30 def changed_files git .added_or_modified .select(&ruby_files) end
offences?()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 36 def offences? stash_me_maybe { rubocop_validator.errors?(changed_files) } end
rubocop_stash?()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 61 def rubocop_stash? rubocop_stash_id end
rubocop_stash_id()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 65 def rubocop_stash_id Array( git.repository.lib .stashes_all .rassoc(RUBOCOP_STASH_NAME) ).first end
ruby_files()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 40 def ruby_files -> (file) { File.extname(file) == '.rb' } end
stash_around() { || ... }
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 50 def stash_around git.repository.lib.stash_save(RUBOCOP_STASH_NAME) yield ensure git.repository.lib.stash_pop(rubocop_stash_id) if rubocop_stash? end
stash_around?()
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 57 def stash_around? options['use_stash'] end
stash_me_maybe() { || ... }
click to toggle source
# File lib/git_hooks/pre_commit/rubocop.rb, line 44 def stash_me_maybe(&blk) return yield unless stash_around? stash_around(&blk) end