Class: MacSetup::HomebrewRunner
- Inherits:
-
Object
- Object
- MacSetup::HomebrewRunner
- Defined in:
- lib/mac_setup/homebrew_runner.rb
Class Method Summary collapse
- .install_brew(formula) ⇒ Object
- .install_cask(cask) ⇒ Object
- .print_args(opts) ⇒ Object
- .quote_args(args) ⇒ Object
- .run(config, _status) ⇒ Object
- .write_brewfile(config, brewfile) ⇒ Object
Class Method Details
.install_brew(formula) ⇒ Object
17 18 19 |
# File 'lib/mac_setup/homebrew_runner.rb', line 17 def self.install_brew(formula) Shell.run("brew install #{formula}") end |
.install_cask(cask) ⇒ Object
21 22 23 |
# File 'lib/mac_setup/homebrew_runner.rb', line 21 def self.install_cask(cask) Shell.run("brew cask install #{cask}") end |
.print_args(opts) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mac_setup/homebrew_runner.rb', line 39 def self.print_args(opts) args = opts["args"] return unless args "args: [#{quote_args(args.sort)}]" end |
.quote_args(args) ⇒ Object
47 48 49 |
# File 'lib/mac_setup/homebrew_runner.rb', line 47 def self.quote_args(args) args.map { |arg| %("#{arg}") }.join(", ") end |
.run(config, _status) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mac_setup/homebrew_runner.rb', line 5 def self.run(config, _status) MacSetup.log("Installing Homebrew brews and casks") do Tempfile.create("Brewfile") do |brewfile| write_brewfile(config, brewfile) File.chmod(0644, brewfile) brewfile.rewind Shell.raw("brew bundle install --file=#{brewfile.path}") end end end |
.write_brewfile(config, brewfile) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mac_setup/homebrew_runner.rb', line 25 def self.write_brewfile(config, brewfile) taps = config.taps.map { |parts| %(tap #{quote_args(parts)}) } 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 brewfile.write((taps + brews + casks).join("\n")) end |