lib/myosx/homebrew.rb in myosx-0.2.1 vs lib/myosx/homebrew.rb in myosx-0.2.2
- old
+ new
@@ -5,34 +5,44 @@
require 'yaml'
require 'git'
require_relative 'config'
class Homebrew < Config
- def initialize
- @config = $global_config['homebrew']
+
+ def config
+ $global_config['homebrew']
end
+ def packages
+ config['packages']
+ end
+
+ def brewfile
+ return File.join($workspace, 'Brewfile')
+ end
+
+ def brewfile_out(packages)
+ output = ''
+ packages.each do |type, package_array|
+ package_array.each do |package|
+ output << "#{type} '#{package}'\n"
+ end
+ end
+ return output
+ end
+
def bundle
system("brew tap Homebrew/bundle")
puts "Updating Brewfile"
- packages = @config['packages']
- brew_packages = packages['brew']
- tap_packages = packages['tap']
- cask_packages = packages['cask']
- File.open(File.join($workspace, 'Brewfile'), "w+") do |f|
- brew_packages.each { |p| f.puts "brew '#{p}'" }
- tap_packages.each { |p| f.puts "tap '#{p}'" }
- cask_packages.each { |p| f.puts "cask '#{p}'" }
- end
- brewfile = File.join($workspace, 'Brewfile')
+ File.open(brewfile, "w+") {
+ |file| file.write(brewfile_out(packages))
+ }
puts "Installing packages from #{brewfile}"
- system("brew bundle --file=#{brewfile}")
+ system("brew", "bundle", "--file=#{brewfile}")
end
def exec
- if @config['manage']
- bundle
- end
+ bundle
end
end