Class: Bundler::GemHelper

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/bundler/gem_helper.rb

Class Attribute Summary (collapse)

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (GemHelper) initialize(base = nil, name = nil)



25
26
27
28
29
30
31
32
# File 'lib/bundler/gem_helper.rb', line 25

def initialize(base = nil, name = nil)
  Bundler.ui = UI::Shell.new
  @base = (base ||= SharedHelpers.pwd)
  gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")]
  raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
  @spec_path = gemspecs.first
  @gemspec = Bundler.load_gemspec(@spec_path)
end

Class Attribute Details

+ (Object) instance

set when install'd.



10
11
12
# File 'lib/bundler/gem_helper.rb', line 10

def instance
  @instance
end

Instance Attribute Details

- (Object) base (readonly)

Returns the value of attribute base



23
24
25
# File 'lib/bundler/gem_helper.rb', line 23

def base
  @base
end

- (Object) gemspec (readonly)

Returns the value of attribute gemspec



23
24
25
# File 'lib/bundler/gem_helper.rb', line 23

def gemspec
  @gemspec
end

- (Object) spec_path (readonly)

Returns the value of attribute spec_path



23
24
25
# File 'lib/bundler/gem_helper.rb', line 23

def spec_path
  @spec_path
end

Class Method Details

+ (Object) gemspec(&block)



16
17
18
19
20
# File 'lib/bundler/gem_helper.rb', line 16

def gemspec(&block)
  gemspec = instance.gemspec
  block.call(gemspec) if block
  gemspec
end

+ (Object) install_tasks(opts = {})



12
13
14
# File 'lib/bundler/gem_helper.rb', line 12

def install_tasks(opts = {})
  new(opts[:dir], opts[:name]).install
end

Instance Method Details

- (Object) build_gem



55
56
57
58
59
60
61
62
63
64
# File 'lib/bundler/gem_helper.rb', line 55

def build_gem
  file_name = nil
  sh("gem build -V '#{spec_path}'") { |out, code|
    file_name = File.basename(built_gem_path)
    FileUtils.mkdir_p(File.join(base, 'pkg'))
    FileUtils.mv(built_gem_path, 'pkg')
    Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
  }
  File.join(base, 'pkg', file_name)
end

- (Object) install



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bundler/gem_helper.rb', line 34

def install
  built_gem_path = nil

  desc "Build #{name}-#{version}.gem into the pkg directory."
  task 'build' do
    built_gem_path = build_gem
  end

  desc "Build and install #{name}-#{version}.gem into system gems."
  task 'install' => 'build' do
    install_gem(built_gem_path)
  end

  desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems"
  task 'release' => 'build' do
    release_gem(built_gem_path)
  end

  GemHelper.instance = self
end

- (Object) install_gem(built_gem_path = nil)



66
67
68
69
70
71
# File 'lib/bundler/gem_helper.rb', line 66

def install_gem(built_gem_path=nil)
  built_gem_path ||= build_gem
  out, _ = sh_with_code("gem install '#{built_gem_path}' --local")
  raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
  Bundler.ui.confirm "#{name} (#{version}) installed."
end

- (Object) release_gem(built_gem_path = nil)



73
74
75
76
77
78
# File 'lib/bundler/gem_helper.rb', line 73

def release_gem(built_gem_path=nil)
  guard_clean
  built_gem_path ||= build_gem
  tag_version { git_push } unless already_tagged?
  rubygem_push(built_gem_path) if gem_push?
end