Parent

Included Modules

Class Index [+]

Quicksearch

Bundler::GemHelper

Attributes

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

Public Class Methods

install_tasks(opts = {}) click to toggle source
    # File lib/bundler/gem_helper.rb, line 9
 9:     def self.install_tasks(opts = {})
10:       dir = opts[:dir] || Dir.pwd
11:       self.new(dir, opts[:name]).install
12:     end
new(base, name = nil) click to toggle source
    # File lib/bundler/gem_helper.rb, line 16
16:     def initialize(base, name = nil)
17:       Bundler.ui = UI::Shell.new(Thor::Base.shell.new)
18:       @base = base
19:       gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "*.gemspec")]
20:       raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
21:       @spec_path = gemspecs.first
22:       @gemspec = Bundler.load_gemspec(@spec_path)
23:     end

Public Instance Methods

build_gem() click to toggle source
    # File lib/bundler/gem_helper.rb, line 42
42:     def build_gem
43:       file_name = nil
44:       sh("gem build '#{spec_path}'") { |out, code|
45:         raise out unless out[/Successfully/]
46:         file_name = File.basename(built_gem_path)
47:         FileUtils.mkdir_p(File.join(base, 'pkg'))
48:         FileUtils.mv(built_gem_path, 'pkg')
49:         Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}"
50:       }
51:       File.join(base, 'pkg', file_name)
52:     end
install() click to toggle source
    # File lib/bundler/gem_helper.rb, line 25
25:     def install
26:       desc "Build #{name}-#{version}.gem into the pkg directory"
27:       task 'build' do
28:         build_gem
29:       end
30: 
31:       desc "Build and install #{name}-#{version}.gem into system gems"
32:       task 'install' do
33:         install_gem
34:       end
35: 
36:       desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems"
37:       task 'release' do
38:         release_gem
39:       end
40:     end
install_gem() click to toggle source
    # File lib/bundler/gem_helper.rb, line 54
54:     def install_gem
55:       built_gem_path = build_gem
56:       out, _ = sh_with_code("gem install '#{built_gem_path}'")
57:       raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
58:       Bundler.ui.confirm "#{name} (#{version}) installed"
59:     end
release_gem() click to toggle source
    # File lib/bundler/gem_helper.rb, line 61
61:     def release_gem
62:       guard_clean
63:       guard_already_tagged
64:       built_gem_path = build_gem
65:       tag_version {
66:         git_push
67:         rubygem_push(built_gem_path)
68:       }
69:     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 104
104:     def clean?
105:       sh_with_code("git diff --exit-code")[1] == 0
106:     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 94
94:     def guard_already_tagged
95:       if sh('git tag').split(/\n/).include?(version_tag)
96:         raise("This tag has already been committed to the repo.")
97:       end
98:     end
guard_clean() click to toggle source
     # File lib/bundler/gem_helper.rb, line 100
100:     def guard_clean
101:       clean? or raise("There are files that need to be committed first.")
102:     end
name() click to toggle source
     # File lib/bundler/gem_helper.rb, line 126
126:     def name
127:       gemspec.name
128:     end
perform_git_push(options = '') click to toggle source
    # File lib/bundler/gem_helper.rb, line 88
88:     def perform_git_push(options = '')
89:       cmd = "git push #{options}"
90:       out, code = sh_with_code(cmd)
91:       raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
92:     end
rubygem_push(path) click to toggle source
    # File lib/bundler/gem_helper.rb, line 72
72:     def rubygem_push(path)
73:       out, _ = sh("gem push '#{path}'")
74:       raise "Gem push failed due to lack of RubyGems.org credentials." if out[/Enter your RubyGems.org credentials/]
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 130
130:     def sh(cmd, &block)
131:       out, code = sh_with_code(cmd, &block)
132:       code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
133:     end
sh_with_code(cmd, &block) click to toggle source
     # File lib/bundler/gem_helper.rb, line 135
135:     def sh_with_code(cmd, &block)
136:       cmd << " 2>&1"
137:       outbuf = ''
138:       Bundler.ui.debug(cmd)
139:       Dir.chdir(base) {
140:         outbuf = `#{cmd}`
141:         if $? == 0
142:           block.call(outbuf) if block
143:         end
144:       }
145:       [outbuf, $?]
146:     end
tag_version() click to toggle source
     # File lib/bundler/gem_helper.rb, line 108
108:     def tag_version
109:       sh "git tag -a -m \"Version #{version}\" #{version_tag}"
110:       Bundler.ui.confirm "Tagged #{version_tag}"
111:       yield if block_given?
112:     rescue
113:       Bundler.ui.error "Untagged #{version_tag} due to error"
114:       sh_with_code "git tag -d #{version_tag}"
115:       raise
116:     end
version() click to toggle source
     # File lib/bundler/gem_helper.rb, line 118
118:     def version
119:       gemspec.version
120:     end
version_tag() click to toggle source
     # File lib/bundler/gem_helper.rb, line 122
122:     def version_tag
123:       "v#{version}"
124:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.