Class: RTask
- Inherits:
-
Object
- Object
- RTask
- Defined in:
- lib/rtask.rb,
lib/rtask/gem.rb,
lib/rtask/spec.rb
Overview
Usage for Rake users
RTask in your Rakefile:
require 'rubygems'
require 'rtask'
RTask.new
Result:
% rake -T
rake clean # Remove any temporary products.
rake clobber # Remove any generated file.
rake clobber_rdoc # Remove rdoc products
rake gem # Create the gem package
rake publish # Upload API documentation
rake rdoc # Build the rdoc HTML Files
rake release # Release new gem version
rake rerdoc # Force a rebuild of the RDOC files
rake tgz # Create the tgz package
Defined Under Namespace
Modules: Gem, UI Classes: Spec
Constant Summary collapse
- VERSION =
"010"
- MESSAGE =
Hash.new
Instance Attribute Summary collapse
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.define_task(description, rule) ⇒ Object
define task.
Instance Method Summary collapse
-
#clean ⇒ Object
Task for cleaning.
-
#gem ⇒ Object
Task for creating gem.
-
#init_spec ⇒ Object
Initialize gem specification.
-
#initialize(config = {:use => :all}) {|_self| ... } ⇒ RTask
constructor
A new instance of RTask.
-
#publish ⇒ Object
Task for uploading API documentation.
-
#rdoc ⇒ Object
Task for generating documents using rdoc.
-
#release ⇒ Object
Task for release the package.
-
#tgz ⇒ Object
Task for creating tgz.
-
#use(*names) ⇒ Object
Specifies to use tasks.
-
#zip ⇒ Object
Task for creating zip.
Constructor Details
#initialize(config = {:use => :all}) {|_self| ... } ⇒ RTask
Returns a new instance of RTask.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rtask.rb', line 28 def initialize(config={:use => :all}) @spec = init_spec @spec.files = manifest @rubyforge = ::RubyForge.new @rubyforge.configure @user = @rubyforge.userconfig @project = @spec.rubyforge_project @package = @spec.name @version = @spec.version @lib_version = config[:version] if config.has_key?(:use) list = config[:use] list -= config[:exclude] if config[:exclude] use(*config[:use]) end yield self if block_given? end |
Instance Attribute Details
#package ⇒ Object (readonly)
Returns the value of attribute package.
26 27 28 |
# File 'lib/rtask.rb', line 26 def package @package end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
26 27 28 |
# File 'lib/rtask.rb', line 26 def project @project end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
26 27 28 |
# File 'lib/rtask.rb', line 26 def spec @spec end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
26 27 28 |
# File 'lib/rtask.rb', line 26 def version @version end |
Class Method Details
.define_task(description, rule) ⇒ Object
define task
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rtask.rb', line 81 def self.define_task(description, rule) name = rule if rule.kind_of?(Hash) name = rule.keys.first end MESSAGE[name] = description define_method("register_task_#{name}") do |rtask| desc description if description task(rule){ rtask.send name if rtask.respond_to?(name) } end end |
Instance Method Details
#clean ⇒ Object
Task for cleaning.
117 118 119 120 |
# File 'lib/rtask.rb', line 117 def clean require 'rake/clean' CLEAN.include ['html', '*.gem', '*.tgz', '*.zip', '.config', '**/.DS_Store'] end |
#gem ⇒ Object
Task for creating gem
170 171 172 |
# File 'lib/rtask.rb', line 170 def gem Gem.build(@spec) end |
#init_spec ⇒ Object
Initialize gem specification.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rtask.rb', line 47 def init_spec # if .rtask exists if File.exist?(".rtask") return YAML.load(File.read(".rtask")) end # if gemspec exists Dir.glob("*.gemspec") do |spec| return RTask::Spec.new(::Gem::Specification.load(spec)) end # if .gemified exists if File.exist?(".gemified") data = YAML.load(File.read(".gemified")) spec = ::Gem::Specification.new spec.summary = data[:summary] spec.email = data[:email] spec.name = data[:name] spec.homepage = data[:homepage] spec.version = data[:version] spec.rubyforge_project = data[:rubyforge_project] # assume gemify's "dependencies" are runtime dependencies data[:dependencies].each do |dep| spec.add_runtime_dependency dep end spec. << data[:author] return RTask::Spec.new(spec) end # no specification return RTask::Spec.new end |
#publish ⇒ Object
Task for uploading API documentation.
135 136 137 138 139 |
# File 'lib/rtask.rb', line 135 def publish require 'rake/contrib/rubyforgepublisher' pub = Rake::RubyForgePublisher.new(@project, @user["username"]) pub.upload end |
#rdoc ⇒ Object
Task for generating documents using rdoc.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rtask.rb', line 123 def rdoc require 'rake/rdoctask' Rake::RDocTask.new do |doc| doc.title = "#{@package}-#{@version} documentation" doc.main = "README.txt" doc.rdoc_files.include("{README,History,License}.txt", "lib/**/*.rb") doc. << "--line-numbers" << "--inline-source" << "-c UTF-8" yield doc if block_given? end end |
#release ⇒ Object
Task for release the package.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/rtask.rb', line 144 def release if @lib_version and @version.to_s != @lib_version.to_s puts "Version confilict between the library and in .gemified" puts "library: " + @lib_version.to_s puts "Gemify : " + @version.to_s exit end filename = "#{@package}-#{@version}" gem = filename + ".gem" tgz = filename + ".tgz" zip = filename + ".zip" if File.exist?(gem) and File.exist?(tgz) and File.exist?(zip) @rubyforge.add_release @project, @package, @version, gem, tgz, zip puts "Released #{gem}, #{tgz}, and #{zip}" else puts "Please make gem and tgz files first: rake gem tgz" exit end end |
#tgz ⇒ Object
Task for creating tgz
177 178 179 180 |
# File 'lib/rtask.rb', line 177 def tgz tgz = "#{@package}-#{@version}.tgz" sh "tar -T Manifest.txt -c -z -f #{tgz}" end |
#use(*names) ⇒ Object
Specifies to use tasks
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rtask.rb', line 96 def use(*names) if names[0] == :all names = [:clean, :rdoc, :publish, :release, :packages] end names.each do |name| register = "register_task_#{name}" case name when :clean, :rdoc send(name) when :packages send(register, self) send("register_task_gem", self) send("register_task_tgz", self) send("register_task_zip", self) else send(register, self) end end end |
#zip ⇒ Object
Task for creating zip
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rtask.rb', line 185 def zip require "zip/zipfilesystem" filename = "#{@package}-#{@version}.zip" rm filename if File.exist?(filename) Zip::ZipFile.open(filename, Zip::ZipFile::CREATE) do |zip| manifest.each do |file| zip.file.open(File.join("#{package}-#{@version}", file), "w") do |out| out.write(File.open(file).read) end end end end |