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
|
# File 'lib/compass_ae_starter_kit/commands/compass_ae.rb', line 20
def run
major, minor, tiny = `rails -v`.gsub!('Rails ', '').gsub!("\n",'').split('.').collect{|version| version.to_i}
if version_allowed?(RAILS_MAJOR, major) and version_allowed?(RAILS_MINOR, minor) and version_allowed?(RAILS_TINY, tiny)
template_path = File.join(File.dirname(__FILE__), '../templates/default_template.rb')
if ARGV.first != "new" and ARGV.first != "dev"
ARGV[0] = "--help"
end
if ARGV.first == "dev"
template_path = File.join(File.dirname(__FILE__), '../templates/development_template.rb')
ARGV[0] = "new"
end
command = ARGV.shift
case command
when '--help'
puts self.banner
when 'new'
app_name = ARGV.shift
raise "The application name is missing!" if app_name.nil?
puts 'Generating Rails infrastructure...'
system "rails new #{app_name} #{ARGV * ' '} -m #{template_path}"
Dir.chdir app_name
puts 'Installing CompassAE migrations and data migrations...'
system "rake compass_ae:install:migrations"
system "rake compass_ae:install:data_migrations"
puts 'Migrating a fresh database...'
system "rake db:migrate"
system "rake db:migrate_data"
end
else
puts "Installed Rails version is not compatible #{[major, minor, tiny].compact.join('.')}, please install #{[RAILS_MAJOR, RAILS_MINOR, RAILS_TINY].compact.join('.')}"
end
end
|