require 'rubygems' require 'rake' require 'rake/testtask' require 'rake/rdoctask' PKG_VERSION = "0.96.4" $VERBOSE = nil TEST_CHANGES_SINCE = Time.now - 600 # Recent tests = changed in last 10 minutes desc "Run all the unit tests" task :default => [ :test, :lines ] # Look up tests for recently modified sources. def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) FileList[source_pattern].map do |path| if File.mtime(path) > touched_since test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb" test if File.exists?(test) end end.compact end desc 'Test recent changes.' Rake::TestTask.new(:rtest) do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + recent_tests('lib/icalendar/*.rb', 'test', since) + recent_tests('lib/icalendar/component/*.rb', 'test/component', since) t.libs << 'test' t.verbose = true t.test_files = touched.uniq end desc "Run the unit tests in test" Rake::TestTask.new(:test) { |t| t.libs << "test" t.test_files = FileList['test/*_test.rb', 'test/component/*_test.rb'] t.verbose = true } # Generate the RDoc documentation Rake::RDocTask.new(:doc) { |rdoc| rdoc.main = 'README' rdoc.rdoc_files.include('lib/**/*.rb', 'README') rdoc.rdoc_files.include('GPL', 'COPYING') rdoc.rdoc_dir = 'docs/api' rdoc.title = "iCalendar -- Internet Calendaring for Ruby" rdoc.options << "--include examples/ --line-numbers --inline-source" rdoc.options << "--accessor=ical_component,ical_property,ical_multi_property" } Gem::manage_gems require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.name = "icalendar" s.version = PKG_VERSION s.homepage = "http://icalendar.rubyforge.org/" s.platform = Gem::Platform::RUBY s.summary = "A ruby implementation of the iCalendar specification (RFC-2445)." s.description = "Implements the iCalendar specification (RFC-2445) in Ruby. This allows for the generation and parsing of .ics files, which are used by a variety of calendaring applications." s.files = FileList["{test,lib,docs,examples}/**/*"].to_a s.files += ["Rakefile", "README", "COPYING", "GPL" ] s.require_path = "lib" s.autorequire = "icalendar" s.has_rdoc = true s.extra_rdoc_files = ["README", "COPYING", "GPL"] s.rdoc_options.concat ['--main', 'README'] s.author = "Jeff Rose" s.email = "rosejn@gmail.com" end Rake::GemPackageTask.new(spec) do |pkg| pkg.gem_spec = spec pkg.need_tar = true pkg.need_zip = true end task :lines do lines = 0 codelines = 0 Dir.foreach("lib/icalendar") { |file_name| next unless file_name =~ /.*rb/ f = File.open("lib/icalendar/" + file_name) while line = f.gets lines += 1 next if line =~ /^\s*$/ next if line =~ /^\s*#/ codelines += 1 end } puts "\n------------------------------\n" puts "Total Lines: #{lines}" puts "Lines of Code: #{codelines}" end