Module: Homebrew::Bundle::Adder Private

Defined in:
bundle/adder.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.add(*args, type:, global:, file:, describe: false) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • args (String)
  • type (Symbol)
  • global (Boolean)
  • file (String)
  • describe (Boolean) (defaults to: false)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'bundle/adder.rb', line 13

def add(*args, type:, global:, file:, describe: false)
  brewfile_path = Brewfile.path(global:, file:)
  brewfile_path.write("") unless brewfile_path.exist?

  brewfile = Brewfile.read(global:, file:)
  content = brewfile.input
  new_content = args.map do |arg|
    desc = case type
    when :brew
      Formulary.factory(arg).desc
    when :cask
      ::Cask::CaskLoader.load(arg).desc
    end

    entry = "#{type} \"#{arg}\""
    if describe && desc.present?
      desc.split("\n").map { |s| "# #{s}\n" }.join + entry
    else
      entry
    end
  end

  content << new_content.join("\n") << "\n"
  path = Dumper.brewfile_path(global:, file:)

  Dumper.write_file path, content
end