Class: MacSetup::HomebrewRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/mac_setup/homebrew_runner.rb

Class Method Summary collapse

Class Method Details

.build_brewfile(config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mac_setup/homebrew_runner.rb', line 19

def self.build_brewfile(config)
  brews = config.brews.map do |name, opts|
    [%(brew "#{name}"), print_args(opts)].compact.join(", ")
  end

  casks = (config.fonts + config.casks + config.quicklook).map do |name|
    "cask #{name}"
  end

  (brews + casks).join("\n")
end

.install_cask(cask) ⇒ Object



15
16
17
# File 'lib/mac_setup/homebrew_runner.rb', line 15

def self.install_cask(cask)
  Shell.run("brew cask install #{cask}")
end


31
32
33
34
35
36
37
38
# File 'lib/mac_setup/homebrew_runner.rb', line 31

def self.print_args(opts)
  args = opts["args"]

  return unless args

  args_str = args.sort.map { |arg| %("#{arg}") }.join(", ")
  "args: [#{args_str}]"
end

.run(config, _status) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/mac_setup/homebrew_runner.rb', line 3

def self.run(config, _status)
  brewfile = build_brewfile(config)

  cmd = [
    "echo << EOF | brew bundle install --file=-",
    brewfile,
    "EOF"
  ]

  Shell.run(cmd.join("\n"))
end