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 = []
  @formula_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

#formula_countObject (readonly)

Returns the value of attribute formula_count.



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

def formula_count
  @formula_count
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

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 @formula_count.zero?
  return if @formula_count == 1 && !force
  return if @caveats.empty?

  oh1 "Caveats"
  @caveats.each do |c|
    ohai c[:formula], 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("%<formula>-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

#formula_installed(f, elapsed_time) ⇒ Object



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

def formula_installed(f, elapsed_time)
  @formula_count += 1
  @install_times.push(formula: f.name, time: elapsed_time)
end

#record_caveats(f, caveats) ⇒ Object



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

def record_caveats(f, caveats)
  @caveats.push(formula: f.name, caveats: caveats)
end