Class: Gem::PackageTask

Inherits:
Rake::PackageTask
  • Object
show all
Defined in:
lib/rubygems/package_task.rb

Overview

Create a package based upon a Gem::Specification. Gem packages, as well as zip files and tar/gzipped packages can be produced by this task.

In addition to the Rake targets generated by Rake::PackageTask, a Gem::PackageTask will also generate the following tasks:

package_dir/name-version.gem”

Create a RubyGems package with the given name and version.

Example using a Gem::Specification:

require 'rubygems'
require 'rubygems/package_task'

spec = Gem::Specification.new do |s|
  s.summary = "Ruby based make-like utility."
  s.name = 'rake'
  s.version = PKG_VERSION
  s.requirements << 'none'
  s.files = PKG_FILES
  s.description = <<-EOF
Rake is a Make-like program implemented in Ruby. Tasks
and dependencies are specified in standard Ruby syntax.
  EOF
end

Gem::PackageTask.new(spec) do |pkg|
  pkg.need_zip = true
  pkg.need_tar = true
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_spec) {|_self| ... } ⇒ PackageTask

Create a Gem Package task library. Automatically define the gem if a block is given. If no block is supplied, then #define needs to be called to define the task.

Yields:

  • (_self)

Yield Parameters:



72
73
74
75
76
# File 'lib/rubygems/package_task.rb', line 72

def initialize(gem_spec)
  init gem_spec
  yield self if block_given?
  define if block_given?
end

Instance Attribute Details

#gem_specObject

Ruby Gem::Specification containing the metadata for this package. The name, version and package_files are automatically determined from the gemspec and don’t need to be explicitly provided.



65
66
67
# File 'lib/rubygems/package_task.rb', line 65

def gem_spec
  @gem_spec
end

Instance Method Details

#defineObject

Create the Rake tasks and actions specified by this Gem::PackageTask. (define is automatically called if a block is given to new).



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rubygems/package_task.rb', line 92

def define
  super

  gem_file = File.basename gem_spec.cache_file
  gem_path = File.join package_dir, gem_file
  gem_dir  = File.join package_dir, gem_spec.full_name

  task :package => [:gem]

  directory package_dir
  directory gem_dir

  desc "Build the gem file #{gem_file}"
  task :gem => [gem_path]

  trace = Rake.application.options.trace
  Gem.configuration.verbose = trace

  file gem_path => [package_dir, gem_dir] + @gem_spec.files do
    chdir(gem_dir) do
      when_writing "Creating #{gem_spec.file_name}" do
        Gem::Package.build gem_spec

        verbose trace do
          mv gem_file, '..'
        end
      end
    end
  end
end

#init(gem) ⇒ Object

Initialization tasks without the “yield self” or define operations.



81
82
83
84
85
86
# File 'lib/rubygems/package_task.rb', line 81

def init(gem)
  super gem.full_name, :noversion
  @gem_spec = gem
  @package_files += gem_spec.files if gem_spec.files
  @fileutils_output = $stdout
end