Class: Messages

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
messages.rb

Overview

A Messages object collects messages that may need to be displayed together at the end of a multi-step brew command run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid



12
13
14
15
16
# File 'messages.rb', line 12

def initialize
  @caveats = []
  @package_count = 0
  @install_times = []
end

Instance Attribute Details

#caveatsObject (readonly)

Returns the value of attribute caveats.



9
10
11
# File 'messages.rb', line 9

def caveats
  @caveats
end

#install_timesObject (readonly)

Returns the value of attribute install_times.



9
10
11
# File 'messages.rb', line 9

def install_times
  @install_times
end

#package_countObject (readonly)

Returns the value of attribute package_count.



9
10
11
# File 'messages.rb', line 9

def package_count
  @package_count
end

Instance Method Details

#display_caveats(force: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'messages.rb', line 32

def display_caveats(force: false)
  return if @package_count.zero?
  return if @package_count == 1 && !force
  return if @caveats.empty?

  oh1 "Caveats"
  @caveats.each do |c|
    ohai c[:package], c[:caveats]
  end
end

#display_install_timesObject



43
44
45
46
47
48
49
50
# File 'messages.rb', line 43

def display_install_times
  return if install_times.empty?

  oh1 "Installation times"
  install_times.each do |t|
    puts format("%<package>-20s %<time>10.3f s", t)
  end
end

#display_messages(force_caveats: false, display_times: false) ⇒ Object



27
28
29
30
# File 'messages.rb', line 27

def display_messages(force_caveats: false, display_times: false)
  display_caveats(force: force_caveats)
  display_install_times if display_times
end

#package_installed(package, elapsed_time) ⇒ Object



22
23
24
25
# File 'messages.rb', line 22

def package_installed(package, elapsed_time)
  @package_count += 1
  @install_times.push(package: package, time: elapsed_time)
end

#record_caveats(package, caveats) ⇒ Object



18
19
20
# File 'messages.rb', line 18

def record_caveats(package, caveats)
  @caveats.push(package: package, caveats: caveats)
end