Parent

Bundler::GemHelper

Attributes

spec_path[R]
base[R]
gemspec[R]

Public Class Methods

install_tasks(opts = nil) click to toggle source
    # 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
new(base, name = nil) click to toggle source
    # 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

Public Instance Methods

build_gem() click to toggle source
    # 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
install() click to toggle source
    # 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
install_gem() click to toggle source
    # 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
release_gem() click to toggle source
    # File lib/bundler/gem_helper.rb, line 62
62:     def release_gem
63:       guard_clean
64:       guard_already_tagged
65:       built_gem_path = build_gem
66:       tag_version {
67:         git_push
68:         rubygem_push(built_gem_path)
69:       }
70:     end

Protected Instance Methods

built_gem_path() click to toggle source
    # 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
clean?() click to toggle source
     # File lib/bundler/gem_helper.rb, line 103
103:     def clean?
104:       sh("git ls-files -dm").split("\n").size.zero?
105:     end
git_push() click to toggle source
    # 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
guard_already_tagged() click to toggle source
    # 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
guard_clean() click to toggle source
     # 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
name() click to toggle source
     # File lib/bundler/gem_helper.rb, line 129
129:     def name
130:       gemspec.name
131:     end
perform_git_push(options = '') click to toggle source
    # 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
rubygem_push(path) click to toggle source
    # 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
sh(cmd, &block) click to toggle source
     # 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
sh_with_code(cmd, &block) click to toggle source
     # 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
tag_version() click to toggle source
     # 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
tagged_sha() click to toggle source
     # 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
version() click to toggle source
     # File lib/bundler/gem_helper.rb, line 121
121:     def version
122:       gemspec.version
123:     end
version_tag() click to toggle source
     # File lib/bundler/gem_helper.rb, line 125
125:     def version_tag
126:       "v#{version}"
127:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.