class Gem::PackageTask
基于Gem::Specification
创建一个包。Gem
包,以及zip文件和tar/gzipped包都可以通过此任务生成。
除了 Rake::PackageTask 生成的 Rake 目标之外,Gem::PackageTask
还会生成以下任务
- “package_dir/name-version.gem”
-
使用给定的名称和版本创建 RubyGems 包。
使用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
属性
gem_spec[RW]
包含此包元数据的 Ruby Gem::Specification
。名称、版本和 package_files 会自动从 gemspec 中确定,无需显式提供。
公共类方法
公共实例方法
define() 点击切换源代码
创建此Gem::PackageTask
指定的 Rake 任务和操作。(如果给 new
提供了块,则会自动调用 define
)。
调用父类方法
# File rubygems/package_task.rb, line 93 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) 点击切换源代码
没有 “yield self” 或 define 操作的初始化任务。
调用父类方法
# File rubygems/package_task.rb, line 82 def init(gem) super gem.full_name, :noversion @gem_spec = gem @package_files += gem_spec.files if gem_spec.files @fileutils_output = $stdout end