Parent

Class Index [+]

Quicksearch

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 = File.dirname(Rake.application.rakefile_location)
 9:       self.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::Base.shell.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, code|
43:         raise out unless out[/Successfully/]
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, code = sh_with_code("gem install #{built_gem_path}")
55:       raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
56:       Bundler.ui.confirm "#{name} (#{version}) installed"
57:     end
release_gem() click to toggle source
    # File lib/bundler/gem_helper.rb, line 59
59:     def release_gem
60:       guard_clean
61:       guard_already_tagged
62:       built_gem_path = build_gem
63:       tag_version {
64:         git_push
65:         rubygem_push(built_gem_path)
66:       }
67:     end

Protected Instance Methods

built_gem_path() click to toggle source
    # File lib/bundler/gem_helper.rb, line 76
76:     def built_gem_path
77:       Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
78:     end
clean?() click to toggle source
     # File lib/bundler/gem_helper.rb, line 102
102:     def clean?
103:       out, code = sh_with_code("git diff --exit-code")
104:       code == 0
105:     end
git_push() click to toggle source
    # File lib/bundler/gem_helper.rb, line 80
80:     def git_push
81:       perform_git_push
82:       perform_git_push ' --tags'
83:       Bundler.ui.confirm "Pushed git commits and tags"
84:     end
guard_already_tagged() click to toggle source
    # File lib/bundler/gem_helper.rb, line 92
92:     def guard_already_tagged
93:       if sh('git tag').split(/\n/).include?(version_tag)
94:         raise("This tag has already been committed to the repo.")
95:       end
96:     end
guard_clean() click to toggle source
     # File lib/bundler/gem_helper.rb, line 98
 98:     def guard_clean
 99:       clean? or raise("There are files that need to be committed first.")
100:     end
name() click to toggle source
     # File lib/bundler/gem_helper.rb, line 125
125:     def name
126:       gemspec.name
127:     end
perform_git_push(options = '') click to toggle source
    # File lib/bundler/gem_helper.rb, line 86
86:     def perform_git_push(options = '')
87:       cmd = "git push #{options}"
88:       out, code = sh_with_code(cmd)
89:       raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
90:     end
rubygem_push(path) click to toggle source
    # File lib/bundler/gem_helper.rb, line 70
70:     def rubygem_push(path)
71:       out, status = sh("gem push #{path}")
72:       raise "Gem push failed due to lack of RubyGems.org credentials." if out[/Enter your RubyGems.org credentials/]
73:       Bundler.ui.confirm "Pushed #{name} #{version} to rubygems.org"
74:     end
sh(cmd, &block) click to toggle source
     # File lib/bundler/gem_helper.rb, line 129
129:     def sh(cmd, &block)
130:       out, code = sh_with_code(cmd, &block)
131:       code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
132:     end
sh_with_code(cmd, &block) click to toggle source
     # File lib/bundler/gem_helper.rb, line 134
134:     def sh_with_code(cmd, &block)
135:       cmd << " 2>&1"
136:       outbuf = ''
137:       Bundler.ui.debug(cmd)
138:       Dir.chdir(base) {
139:         outbuf = `#{cmd}`
140:         if $? == 0
141:           block.call(outbuf) if block
142:         end
143:       }
144:       [outbuf, $?]
145:     end
tag_version() click to toggle source
     # File lib/bundler/gem_helper.rb, line 107
107:     def tag_version
108:       sh "git tag -a -m \"Version #{version}\" #{version_tag}"
109:       Bundler.ui.confirm "Tagged #{version_tag}"
110:       yield if block_given?
111:     rescue
112:       Bundler.ui.error "Untagged #{version_tag} due to error"
113:       sh_with_code "git tag -d #{version_tag}"
114:       raise
115:     end
version() click to toggle source
     # File lib/bundler/gem_helper.rb, line 117
117:     def version
118:       gemspec.version
119:     end
version_tag() click to toggle source
     # File lib/bundler/gem_helper.rb, line 121
121:     def version_tag
122:       "v#{version}"
123:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.