forked from holidays/holidays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
62 lines (50 loc) · 1.62 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$:.unshift File.expand_path('../lib', __FILE__)
$:.unshift File.expand_path('../test', __FILE__)
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yaml'
require 'fileutils'
require 'holidays'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.test_files = FileList['test/**/test_*.rb']
end
task :default => :test
namespace :generate do
DATA_PATH = 'data'
desc 'Generate the holiday definition files'
task :definitions 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}" }.uniq
module_src, test_src = Holidays.parse_definition_files_and_return_source(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').exclude(/version/).each do |str|
file.puts('* ' + str.gsub(/^lib\/|\.rb$/, ''))
end
end
puts "Updated manifest file."
end
end
task :generate => ['generate:definitions', 'generate:manifest']