forked from benschwarz/postie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
106 lines (91 loc) · 2.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'rubygems'
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "postie"
gem.summary = %Q{A Sinatra based Rack middleware for Australian postcodes}
gem.email = "[email protected]"
gem.homepage = "http://github.com/benschwarz/postie"
gem.authors = ["Ben Schwarz"]
gem.add_dependency("sinatra", ">= 0.9.2")
gem.add_dependency("dm-core")
gem.add_dependency("dm-serializer")
gem.add_dependency("json")
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = false
end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end
begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)
rescue LoadError
task :features do
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
end
end
task :default => :test
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
if File.exist?('VERSION.yml')
config = YAML.load(File.read('VERSION.yml'))
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
else
version = ""
end
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "postcode #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
task :environment do
require 'lib/postie'
end
namespace :db do
task :import => :environment do
gem 'fastercsv'
require 'fastercsv'
require 'open-uri'
DataMapper.auto_migrate!
url = 'http://www1.auspost.com.au/download/pc-full.zip'
zip_file = File.join(File.dirname(__FILE__), 'db', 'pc-full.zip')
chdir File.join(File.dirname(__FILE__), 'db') do
open url do |source|
zip = File.open(zip_file, 'w')
while chunk = source.read(4096)
zip << chunk
end
zip.close
end
`unzip -o pc-full.zip`
csv_file = Dir.glob('*.csv').first
postcodes = FasterCSV.read(File.join(File.dirname(__FILE__), "db", csv_file))
postcodes.each do |(post_code, name, state_name, comments, _, _, _, _, _, category)|
#post_code = sprintf("%04d", post_code.to_i)
#state = Postie::State.first_or_create(:abbreviation => state_name)
#Postie::Locality.create(:post_code => post_code, :name => name, :state => state, :comments => comments)
end
File.unlink(csv_file)
File.unlink(zip_file)
end
end
end