Class: Overcommit::Reporter

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

Instance Method Summary collapse

Constructor Details

#initialize(name, checks) ⇒ Reporter

Returns a new instance of Reporter.



3
4
5
6
7
8
# File 'lib/overcommit/reporter.rb', line 3

def initialize(name, checks)
  @name    = name
  @checks  = checks
  @width   = 60 - (@checks.map { |s| s.friendly_name.length }.max || 0)
  @results = []
end

Instance Method Details



20
21
22
# File 'lib/overcommit/reporter.rb', line 20

def print_header
  log.log "Running #{@name} checks"
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/overcommit/reporter.rb', line 24

def print_result
  log.log # Newline

  case final_result
  when :good
    log.success "+++ All #{@name} checks passed"
    exit 0
  when :bad
    log.error "!!! One or more #{@name} checks failed"
    exit 1
  when :stop
    log.warning "*** One or more #{@name} checks needs attention"
    log.warning '*** If you really want to commit, use SKIP_CHECKS'
    log.warning "*** (takes a space-separated list of checks to skip, or 'all')"
    exit 1
  end
end

#with_status(check, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/overcommit/reporter.rb', line 10

def with_status(check, &block)
  title = "  Checking #{check.name}"
  log.partial title unless check.stealth?

  status, output = yield

  print_incremental_result(title, status, output, check.stealth?)
  @results << status
end