# -*- ruby -*- require 'formula' require 'fileutils' class RubyGemsDownloadStrategy < AbstractDownloadStrategy def fetch ohai "Fetching bcat from gem source" HOMEBREW_CACHE.cd do ENV['GEM_SPEC_CACHE'] = "#{HOMEBREW_CACHE}/gem_spec_cache" system "gem", "fetch", "bcat", "--version", resource.version end end def cached_location Pathname.new("#{HOMEBREW_CACHE}/bcat-#{resource.version}.gem") end def clear_cache cached_location.unlink if cached_location.exist? end end class GemBcat < Formula url "bcat", :using => RubyGemsDownloadStrategy version "0.6.2" def install # Copy user's RubyGems config to temporary build home. buildpath_gemrc = "#{ENV['HOME']}/.gemrc" if File.exists?('/Users/********/.gemrc') && !File.exists?(buildpath_gemrc) FileUtils.cp('/Users/********/.gemrc', buildpath_gemrc) end # set GEM_HOME and GEM_PATH to make sure we package all the dependent gems # together without accidently picking up other gems on the gem path since # they might not be there if, say, we change to a different rvm gemset ENV['GEM_HOME']="#{prefix}" ENV['GEM_PATH']="#{prefix}" rubybindir = '/usr/local/bin' gem_path = "#{rubybindir}/gem" ruby_path = "#{rubybindir}/ruby" system gem_path, "install", cached_download, "--no-ri", "--no-rdoc", "--no-wrapper", "--no-user-install", "--install-dir", prefix, "--bindir", bin raise "gem install 'bcat' failed with status #{$?.exitstatus}" unless $?.success? bin.rmtree if bin.exist? bin.mkpath brew_gem_prefix = prefix+"gems/bcat-#{version}" completion_for_bash = Dir[ "#{brew_gem_prefix}/completion{s,}/bcat.{bash,sh}", "#{brew_gem_prefix}/**/bcat{_,-}completion{s,}.{bash,sh}" ].first bash_completion.install completion_for_bash if completion_for_bash completion_for_zsh = Dir[ "#{brew_gem_prefix}/completions/bcat.zsh", "#{brew_gem_prefix}/**/bcat{_,-}completion{s,}.zsh" ].first zsh_completion.install completion_for_zsh if completion_for_zsh gemspec = Gem::Specification::load("#{prefix}/specifications/bcat-#{version}.gemspec") ruby_libs = Dir.glob("#{prefix}/gems/*/lib") gemspec.executables.each do |exe| file = Pathname.new("#{brew_gem_prefix}/#{gemspec.bindir}/#{exe}") (bin+file.basename).open('w') do |f| f << <<-RUBY #!#{ruby_path} --disable-gems ENV['GEM_HOME']="#{prefix}" ENV['GEM_PATH']="#{prefix}" require 'rubygems' $:.unshift(#{ruby_libs.map(&:inspect).join(",")}) load "#{file}" RUBY end end end end