-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
61 lines (53 loc) · 1.99 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
task :environment do
require File.expand_path( "../config/environment", __FILE__ )
end
task :default => ["assets:precompile"]
namespace :assets do
def precompiled_assets
[].tap do |arr|
arr.concat Dir[File.join(APP_ROOT, "assets", "images", "*")].map { |f| File.basename(f) }
arr << "thirty_one.css"
arr << "application.js"
end
end
task :precompile => :environment do
target = File.join(APP_ROOT, "public", "assets")
@_env = ThirtyOne.sprockets_environment
@_env.each_logical_path do |logical_path|
next unless precompiled_assets.include?(logical_path)
if asset = @_env.find_asset(logical_path)
puts "Precompile #{logical_path}"
filename = File.join(target, asset.digest_path)
FileUtils.mkdir_p File.dirname(filename)
asset.write_to(filename)
# asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
end
end
end
end
namespace :db do
desc "Migrate the database"
task :migrate => [:environment] do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate( File.expand_path("../db/migrate", __FILE__) )
end
namespace :schema do
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
task :dump => :environment do
require 'active_record/schema_dumper'
File.open(ENV['SCHEMA'] || "#{APP_ROOT}/db/schema.rb", "w") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
Rake::Task["db:schema:dump"].reenable
end
desc "Load a schema.rb file into the database"
task :load => :environment do
file = ENV['SCHEMA'] || "#{APP_ROOT}/db/schema.rb"
if File.exists?(file)
load(file)
else
abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{APP_ROOT}/config/boot.rb to limit the frameworks that will be loaded}
end
end
end
end