-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
111 lines (94 loc) · 2.88 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
107
108
109
110
111
require 'csv'
require 'active_record'
require 'uri'
require 'yaml'
require 'logger'
require 'rake'
task :default => "orga:show_todos"
namespace :orga do
desc "ToDos"
task :show_todos do
puts File.read('TODOS.TXT')
end
end
namespace :web do
desc "Run the sinatra app"
task :start do
system("bundle exec unicorn -c unicorn.rb -Ilib -E development -D")
end
desc "Stop the sinatra app"
task :stop do
if File.exists?('tmp/pids/unicorn.pid') then
@pid = File.read('tmp/pids/unicorn.pid').strip
if File.exists?("/proc/#{@pid}") then
Process::kill("SIGINT", @pid.to_i)
end
end
end
end
namespace :db do
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end
desc "Fill the database with data"
task :load_data => :environment do
scheme_description = YAML.load_file(File.join('config','scheme_description.yml'))
data = CSV.read(File.join('data','weather.data'), { col_sep: ':' })
class Measurement < ActiveRecord::Base
validates_uniqueness_of :DT # FIXME: make this more generell
end
data.each do |d|
i = 0
scheme_description.each do |key, value|
scheme_description[key] = d[i] unless d[i] == "i"
i += 1
end
Measurement.create scheme_description
end
end
desc "Fill the database with states"
task :load_states => :environment do
scheme_description = YAML.load_file(File.join('config','states_description.yml'))
data = CSV.read(File.join('data','weather.status'), { col_sep: ':' })
class State < ActiveRecord::Base
end
data.each do |d|
i = 0
scheme_description.each do |key, value|
scheme_description[key] = d[i] unless d[i] == "i"
i += 1
end
State.create scheme_description
end
end
task :environment do
if (ENV['DATABASE_URL']) then
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/app-dev')
db_config = {
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:port => db.port,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8',
}
else
Dir.mkdir('log') unless Dir.exists?('log')
db_config = YAML::load(File.open(File.join('config','database.yml')))
# ActiveRecord::Base.logger = Logger.new(File.open(File.join('log','database.log'), 'a'))
end
ActiveRecord::Base.establish_connection(db_config)
end
end
namespace :test do
begin
require 'rspec/core/rake_task'
desc "run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/*_spec.rb'
end
rescue LoadError
end
end