Bump Chunker to 1.0.0 (release), updates for rspec 2.
#!/usr/bin/env rake#require 'rubygems'require 'pathname'require 'rake'require 'rspec'require 'rspec/core/rake_task'require 'rake/packagetask'require 'rake/gempackagetask'require 'rubygems/installer'require 'rubygems/uninstaller'######################################################################### P A T H S A N D F I L E S######################################################################BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }SPECDIR = BASEDIR + 'spec'SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )LIBDIR = BASEDIR + 'lib'LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES######################################################################### H E L P E R S######################################################################### Given a +file+ path, find the first captured match of +pattern+,### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.)###def find_pattern( file, pattern ) ver = nil File.open( file ) do |f| ver = f.each do |line| break $1 if line =~ pattern end end return ver.is_a?( String ) ? ver : 'UNKNOWN'end######################################################################### P A C K A G E C O N S T A N T S######################################################################PKG_NAME = 'chunker'PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"######################################################################### T A S K S######################################################################task :test => 'test:spec'task :default => :test# task :default => [ :test, :package ]namespace :test do desc 'Generate verbose and pretty output' RSpec::Core::RakeTask.new( :spec ) do |task| task.pattern = SPEC_FILES task.rspec_opts = ['-b', '-fd', '-c'] end desc 'Generate quiet non-colored plain-text output' RSpec::Core::RakeTask.new( :quiet ) do |task| task.pattern = SPEC_FILES task.rspec_opts = ['-f', 'p'] endend### Task: generate ctags### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.###desc "Generate a ctags 'tags' file from Chunker source"task :ctags do sh "ctags -R #{LIBDIR}"end### Task: Create gem from source###gem = Gem::Specification.new do |gem| gem.summary = "A convenience library for parsing __END__ tokens consistently." gem.name = PKG_NAME gem.version = PKG_VERSION gem.author = 'Mahlon E. Smith' gem.email = 'mahlon@martini.nu' gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker' gem.has_rdoc = true gem.files = RELEASE_FILES. collect {|f| f.relative_path_from(BASEDIR).to_s } gem.test_files = SPEC_FILES. collect {|f| f.relative_path_from(BASEDIR).to_s } gem.description = <<-EOF Ruby provides an automatic constant called DATA, which is an IO object that references all text in the current file under an __END__ token. I find it convenient to use the __END__ area to store all sorts of stuff, rather than have to worry about distributing separate files. The DATA constant is determined from whatever ruby believes $0 to be. It doesn't work inside of other required libraries, so you'll see stuff like this all the time: END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last It works, but it's more work than I want to do. Chunker solves this by parsing __END__ tokens for you, and making it available in the form of a 'DATA_END' constant. It installs this constant into the class that includes Chunker, so you can use it again and again, assuming you use a different file for each class. It also automatically parses out other things that look like tokens, so you can easily have multiple, distinct documents all embedded into the __END__ block. EOFendRake::GemPackageTask.new( gem ) do |pkg| pkg.need_zip = true pkg.need_tar = true pkg.need_tar_bz2 = trueend### Task: install###task :install_gem => [ :package ] do $stderr.puts installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" ) installer.installendtask :install => [ :install_gem ]### Task: uninstall###task :uninstall_gem do uninstaller = Gem::Uninstaller.new( PKG_NAME ) uninstaller.uninstallendtask :uninstall => [ :uninstall_gem ]