Object
# File lib/bundler/gem_helper.rb, line 7 7: def self.install_tasks(opts = nil) 8: dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1] 9: GemHelper.new(dir, opts && opts[:name]).install 10: end
# File lib/bundler/gem_helper.rb, line 14 14: def initialize(base, name = nil) 15: Bundler.ui = UI::Shell.new(Thor::Shell::Color.new) 16: @base = base 17: gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "*.gemspec")] 18: raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 19: @spec_path = gemspecs.first 20: @gemspec = Bundler.load_gemspec(@spec_path) 21: end
# File lib/bundler/gem_helper.rb, line 40 40: def build_gem 41: file_name = nil 42: sh("gem build #{spec_path}") { |out, err| 43: raise err if err[/ERROR/] 44: file_name = File.basename(built_gem_path) 45: FileUtils.mkdir_p(File.join(base, 'pkg')) 46: FileUtils.mv(built_gem_path, 'pkg') 47: Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}" 48: } 49: File.join(base, 'pkg', file_name) 50: end
# File lib/bundler/gem_helper.rb, line 23 23: def install 24: desc "Build #{name}-#{version}.gem into the pkg directory" 25: task 'build' do 26: build_gem 27: end 28: 29: desc "Build and install #{name}-#{version}.gem into system gems" 30: task 'install' do 31: install_gem 32: end 33: 34: desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems" 35: task 'release' do 36: release_gem 37: end 38: end
# File lib/bundler/gem_helper.rb, line 52 52: def install_gem 53: built_gem_path = build_gem 54: out, err, code = sh_with_code("gem install #{built_gem_path}") 55: if err[/ERROR/] 56: Bundler.ui.error err 57: else 58: Bundler.ui.confirm "#{name} (#{version}) installed" 59: end 60: end
# File lib/bundler/gem_helper.rb, line 78 78: def built_gem_path 79: Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last 80: end
# File lib/bundler/gem_helper.rb, line 103 103: def clean? 104: sh("git ls-files -dm").split("\n").size.zero? 105: end
# File lib/bundler/gem_helper.rb, line 82 82: def git_push 83: perform_git_push 84: perform_git_push ' --tags' 85: Bundler.ui.confirm "Pushed git commits and tags" 86: end
# File lib/bundler/gem_helper.rb, line 93 93: def guard_already_tagged 94: if sh('git tag').split(/\n/).include?(version_tag) 95: raise("This tag has already been committed to the repo.") 96: end 97: end
# File lib/bundler/gem_helper.rb, line 99 99: def guard_clean 100: clean? or raise("There are files that need to be committed first.") 101: end
# File lib/bundler/gem_helper.rb, line 129 129: def name 130: gemspec.name 131: end
# File lib/bundler/gem_helper.rb, line 88 88: def perform_git_push(options = '') 89: out, err, code = sh_with_code "git push --quiet#{options}" 90: raise err unless err == '' 91: end
# File lib/bundler/gem_helper.rb, line 73 73: def rubygem_push(path) 74: sh("gem push #{path}") 75: Bundler.ui.confirm "Pushed #{name} #{version} to rubygems.org" 76: end
# File lib/bundler/gem_helper.rb, line 133 133: def sh(cmd, &block) 134: out, err, code = sh_with_code(cmd, &block) 135: code == 0 ? out : raise(out.empty? ? err : out) 136: end
# File lib/bundler/gem_helper.rb, line 138 138: def sh_with_code(cmd, &block) 139: outbuf, errbuf = '', '' 140: Dir.chdir(base) { 141: stdin, stdout, stderr = *Open3.popen3(cmd) 142: if $? == 0 143: outbuf, errbuf = stdout.read, stderr.read 144: block.call(outbuf, errbuf) if block 145: end 146: } 147: [outbuf, errbuf, $?] 148: end
# File lib/bundler/gem_helper.rb, line 107 107: def tag_version 108: sh "git tag -am 'Version #{version}' #{version_tag}" 109: Bundler.ui.confirm "Tagged #{tagged_sha} with #{version_tag}" 110: yield if block_given? 111: rescue 112: Bundler.ui.error "Untagged #{tagged_sha} with #{version_tag} due to error" 113: sh "git tag -d #{version_tag}" 114: raise 115: end
# File lib/bundler/gem_helper.rb, line 117 117: def tagged_sha 118: sh("git show-ref --tags #{version_tag}").split(' ').first[0, 8] 119: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.