Class: Messages

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/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

#initializeMessages

Returns a new instance of Messages.


9
10
11
12
13
# File 'Library/Homebrew/messages.rb', line 9

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

Instance Attribute Details

#caveatsObject (readonly)

Returns the value of attribute caveats


7
8
9
# File 'Library/Homebrew/messages.rb', line 7

def caveats
  @caveats
end

#formula_countObject (readonly)

Returns the value of attribute formula_count


7
8
9
# File 'Library/Homebrew/messages.rb', line 7

def formula_count
  @formula_count
end

#install_timesObject (readonly)

Returns the value of attribute install_times


7
8
9
# File 'Library/Homebrew/messages.rb', line 7

def install_times
  @install_times
end

Instance Method Details

#display_caveatsObject


29
30
31
32
33
34
35
36
37
# File 'Library/Homebrew/messages.rb', line 29

def display_caveats
  return if @formula_count <= 1
  return if @caveats.empty?

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

#display_install_timesObject


39
40
41
42
43
44
45
46
# File 'Library/Homebrew/messages.rb', line 39

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(display_times: false) ⇒ Object


24
25
26
27
# File 'Library/Homebrew/messages.rb', line 24

def display_messages(display_times: false)
  display_caveats
  display_install_times if display_times
end

#formula_installed(f, elapsed_time) ⇒ Object


19
20
21
22
# File 'Library/Homebrew/messages.rb', line 19

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

#record_caveats(f, caveats) ⇒ Object


15
16
17
# File 'Library/Homebrew/messages.rb', line 15

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