Class: KitchenInspector::Inspector::StatusReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen-inspector/inspector/report/status_reporter.rb

Overview

Provides functions to report single or global status

Class Method Summary collapse

Class Method Details

.global_status(dependencies) ⇒ Object

Return a global status



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kitchen-inspector/inspector/report/status_reporter.rb', line 32

def global_status(dependencies)
  result = nil
  dependencies.each do |dep|
    status = single_status(dep)

    if status
      result = status
      break
    end
  end

  unless result
    result = {:mark => TICK_MARK, :color => :green, :code => :up_to_date}
  end

  ["Status: #{result[:code]} (#{result[:mark]})".send(result[:color]), result[:code]]
end

.mark_structure(status) ⇒ Object

Given a status return instructions on how to draw it



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/kitchen-inspector/inspector/report/status_reporter.rb', line 70

def mark_structure(status)
  case status
    when :err_req, :err_chef
      {:mark => STATUSES[status], :color => :red, :code => status }
    when :err_repo
      {:mark => STATUSES[status], :color => :yellow, :code => status }
    when :warn_outofdate_repo
      {:mark => STATUSES[status], :color => :light_red, :code => status, :style => :bold }
    when :warn_req
      {:mark => STATUSES[status], :color => :yellow, :code => status, :style => :bold }
    when :warn_mismatch_repo
      {:mark => STATUSES[status], :color => :light_red, :code => status, :style => :bold }
    when :warn_chef
      {:mark => STATUSES[status], :color => :blue, :code => status, :style => :bold }
    when :warn_notunique_repo
      {:mark => STATUSES[status], :color => :light_red, :code => status }
    when :up_to_date
      {:mark => STATUSES[status], :color => :green, :code => status }
    else
      raise StandardError, "Unknown status #{status}"
  end
end

.single_status(dep) ⇒ Object

Return a dependency local status if different from up-to-date



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen-inspector/inspector/report/status_reporter.rb', line 51

def single_status(dep)
  return mark_structure(:err_req) if dep.status == :err_req

  return mark_structure(:err_repo) if dep.repomanager[:status] == :err_repo

  return mark_structure(:warn_outofdate_repo) if dep.repomanager[:status] == :warn_outofdate_repo

  return mark_structure(:warn_req) if dep.status == :warn_req

  return mark_structure(:warn_mismatch_repo) if dep.repomanager[:status] == :warn_mismatch_repo

  return mark_structure(:warn_chef) if dep.chef[:status] == :warn_chef

  return mark_structure(:warn_notunique_repo) if dep.repomanager[:status] == :warn_notunique_repo

  nil
end

.status_to_mark(status) ⇒ Object

Given a status draw a mark



94
95
96
97
98
99
100
101
# File 'lib/kitchen-inspector/inspector/report/status_reporter.rb', line 94

def status_to_mark(status)
  mark = mark_structure(status)

  result = mark[:mark]
  result = result.send(mark[:style]) if mark[:style]
  result = result.send(mark[:color])
  result
end