forked from karmi/marley
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
91 lines (74 loc) · 2.65 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
require 'rubygems'
require 'activerecord'
require 'rake'
require 'ftools'
require 'vendor/akismetor'
CONFIG = YAML.load_file( File.join(File.dirname(__FILE__), 'config', 'config.yml') ) unless defined? CONFIG
module Marley
DATA_DIRECTORY = File.join(File.dirname(__FILE__), CONFIG['data_directory']) unless defined? DATA_DIRECTORY
end
%w{post comment}.each { |f| require File.join(File.dirname(__FILE__), 'app', 'marley', f) }
task :default => 'app:start'
namespace :app do
desc "Install the fresh application"
task :install do
Rake::Task['app:install:create_data_directory'].invoke
Rake::Task['app:install:create_database'].invoke
Rake::Task['app:install:create_sample_article'].invoke
Rake::Task['app:install:create_sample_comment'].invoke
puts "* Starting application in development mode"
Rake::Task['app:start'].invoke
end
namespace :install do
task :create_data_directory do
puts "* Creating data directory in " + Marley::DATA_DIRECTORY
FileUtils.mkdir_p( Marley::DATA_DIRECTORY )
end
task :create_database do
puts "* Creating comments SQLite database in #{Marley::DATA_DIRECTORY}/comments.db"
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3',
:database => File.join(Marley::DATA_DIRECTORY, 'comments.db')
)
load( File.join( File.dirname(__FILE__), 'config', 'db_create_comments.rb' ) )
end
task :create_sample_article do
puts "* Creating sample article"
FileUtils.cp_r( File.join(File.dirname(__FILE__), 'app', 'test', 'fixtures', '001-test-article'), Marley::DATA_DIRECTORY )
end
task :create_sample_comment do
puts "* Creating sample comment"
Marley::Comment.create( :author => 'John Doe',
:email => '[email protected]',
:body => 'Lorem ipsum dolor sit amet',
:post_id => 'test-article' )
end
task :open_in_browser do
`open http://localhost:4567` if RUBY_PLATFORM =~ /darwin/
end
end
desc 'Start application in development'
task :start do
exec "ruby app/marley.rb"
end
desc "Run tests for the application"
task :test do
exec "cd app/test; ruby marley_test.rb"
end
end
namespace :data do
task :sync do
# TODO : use Git
exec "cap data:sync"
end
end
namespace :server do
task :start do
exec "cd app; thin -R rackup.ru -d -P ../tmp/pids/thin.pid -l ../log/production.log -e production -p 4500 start"
end
task :stop do
exec "thin stop"
end
task :restart do
exec "thin restart"
end
end