aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/gem_helper.rb
diff options
context:
space:
mode:
authorAkinori MUSHA <knu@idaemons.org>2012-01-20 17:14:59 +0900
committerAkinori MUSHA <knu@idaemons.org>2012-01-20 17:14:59 +0900
commit61fea0c88c363ff92e6badfd5c6a11feb0d4d6a3 (patch)
tree88d699985f44dc986fddcd68b076945f19c83d2d /lib/bundler/gem_helper.rb
parent663cc6d2bd4f8ce1588bdfed7bb5c5af06d296a0 (diff)
downloadbundler-61fea0c88c363ff92e6badfd5c6a11feb0d4d6a3.tar.gz
Add Bundler::GemHelper.gemspec.
This method provides a way to access the Gem::Specification object generated from the gemspec file from within a Rakefile generated by `bundle gem'. You can keep DRY by using it to pull in attributes like `test_files', `extra_rdoc_files' and `extensions' for building tasks like `test', `rdoc' and `compile', respectively.
Diffstat (limited to 'lib/bundler/gem_helper.rb')
-rw-r--r--lib/bundler/gem_helper.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb
index 2de7aeb0..74cd4f85 100644
--- a/lib/bundler/gem_helper.rb
+++ b/lib/bundler/gem_helper.rb
@@ -6,16 +6,26 @@ module Bundler
class GemHelper
include Rake::DSL if defined? Rake::DSL
- def self.install_tasks(opts = {})
- dir = opts[:dir] || Dir.pwd
- self.new(dir, opts[:name]).install
+ class << self
+ # set when install'd.
+ attr_accessor :instance
+
+ def install_tasks(opts = {})
+ new(opts[:dir], opts[:name]).install
+ end
+
+ def gemspec(&block)
+ gemspec = instance.gemspec
+ block.call(gemspec) if block
+ gemspec
+ end
end
attr_reader :spec_path, :base, :gemspec
- def initialize(base, name = nil)
+ def initialize(base = nil, name = nil)
Bundler.ui = UI::Shell.new(Thor::Base.shell.new)
- @base = base
+ @base = (base ||= Dir.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
@@ -37,6 +47,8 @@ module Bundler
task 'release' do
release_gem
end
+
+ GemHelper.instance = self
end
def build_gem