holidays/rakefile.rb

106 lines
3 KiB
Ruby
Raw Normal View History

$:.unshift File.expand_path('../lib', __FILE__)
2008-12-30 20:40:21 +01:00
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'yaml'
require 'fileutils'
require 'holidays'
require File.expand_path('data/build_defs')
2008-12-30 20:40:21 +01:00
desc 'Run all tests'
task :test => ["test:lib", "test:defs"]
namespace :test do
desc 'Run the unit tests.'
2010-03-04 09:36:59 +01:00
Rake::TestTask.new(:defs) do |t|
2008-12-30 20:40:21 +01:00
t.libs << 'lib'
t.test_files = FileList['test/defs/test*.rb'].exclude('test_helper.rb')
t.verbose = false
end
desc 'Run the definition tests.'
2010-03-04 09:36:59 +01:00
Rake::TestTask.new(:lib) do |t|
2008-12-30 20:40:21 +01:00
t.libs << 'lib'
t.test_files = FileList['test/test*.rb'].exclude('test_helper.rb')
t.verbose = false
end
end
task :doc => ["defs:manifest", :rdoc]
desc 'Generate documentation.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = 'Ruby Holidays Gem'
rdoc.options << '--all' << '--inline-source' << '--line-numbers'
rdoc.options << '--charset' << 'utf-8'
rdoc.rdoc_files.include('README.rdoc')
2010-12-31 23:23:39 +01:00
rdoc.rdoc_files.include('data/SYNTAX.rdoc')
2008-12-30 20:40:21 +01:00
rdoc.rdoc_files.include('lib/holidays/MANIFEST')
rdoc.rdoc_files.include('REFERENCES')
rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('LICENSE')
rdoc.rdoc_files.include('lib/*.rb')
end
desc 'Definition file tasks'
namespace :defs do
DATA_PATH = 'data'
2008-12-31 01:48:56 +01:00
2008-12-30 20:40:21 +01:00
desc 'Build holiday definition files'
task :build_all do
# load the index
def_index = YAML.load_file("#{DATA_PATH}/index.yaml")
# create a dir for the generated tests
FileUtils.mkdir_p('test/defs')
def_index['defs'].each do |region, files|
puts "Building #{region} definition module:"
files = files.collect { |f| "#{DATA_PATH}/#{f}" }
files.uniq!
module_src, test_src = parse_holiday_defs(region, files)
File.open("lib/holidays/#{region.downcase.to_s}.rb","w") do |file|
file.puts module_src
end
unless test_src.empty?
File.open("test/defs/test_defs_#{region.downcase.to_s}.rb","w") do |file|
file.puts test_src
end
end
puts "Done.\n\n"
end
end
desc 'Build the definition manifest.'
task :manifest do
File.open("lib/holidays/MANIFEST","w") do |file|
file.puts <<-EOH
==== Regional definitions
The following definition files are included in this installation:
EOH
FileList.new('lib/holidays/*.rb').each do |str|
file.puts('* ' + str.gsub(/^lib\/|\.rb$/, ''))
end
end
end
end
begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
2010-11-12 22:36:52 +01:00
gemspec.name = "holidays"
gemspec.summary = "A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!"
gemspec.description = "A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!"
2010-11-12 22:36:52 +01:00
gemspec.email = "code@dunae.ca"
gemspec.homepage = "https://github.com/alexdunae/holidays"
gemspec.version = Holidays::VERSION
gemspec.authors = ["Alex Dunae", "Rowan Crawford"]
end
rescue LoadError
puts "Jeweler not available. Install it with: gem install jeweler"
end