Class: HerokuDeployment::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_deployment.rb

Instance Method Summary collapse

Constructor Details

#initializeRails

Returns a new instance of Rails.



6
7
8
# File 'lib/heroku_deployment.rb', line 6

def initialize
  HerokuDeployment::Config.commit_files = []
end

Instance Method Details

#db_migrateObject



28
29
30
# File 'lib/heroku_deployment.rb', line 28

def db_migrate
  system %(heroku rake db:migrate --app #{HerokuDeployment::Config.app})
end

#deployObject



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
# File 'lib/heroku_deployment.rb', line 32

def deploy
  HerokuDeployment::Git.push
  unless HerokuDeployment::Config.generate_url.to_s == ""
    raise "JS & CSS generation failed" unless generate_css_and_js
  end
  if HerokuDeployment::Config.compress_js
    HerokuDeployment::Config.js_files.each do |js|
      HerokuDeployment::Packer.compress_js("public/javascripts/#{js}")
    end
  end
  if HerokuDeployment::Config.compress_css
    HerokuDeployment::Config.css_files.each do |css|
      HerokuDeployment::Packer.compress_css("public/stylesheets/#{css}")
    end
  end
  HerokuDeployment::Git.commit
  unless HerokuDeployment::Config.skip_push_to_heroku
    HerokuDeployment::Git.push_remote
    HerokuDeployment::Git.pull_remote
  else
    puts "SKIPPING HEROKU DEPLOYMENT"
  end
  HerokuDeployment::Git.push
  HerokuDeployment::Git.pull
  db_migrate if HerokuDeployment::Config.migrate
  HerokuDeployment::Hoptoad.deployed! if HerokuDeployment::Config.hoptoad
end

#generate_css_and_jsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/heroku_deployment.rb', line 10

def generate_css_and_js
  js_files = HerokuDeployment::Config.js_files
  css_files = HerokuDeployment::Config.css_files
  puts "Generating all the Javascripts and CSS as production"
  system %(rm #{(js_files.collect{|j| "public/javascripts/#{j}"} + css_files.collect{|c| "public/stylesheets/#{c}"}).join(" ")} 2> /dev/null)
  HerokuDeployment::Config.commit_files << 'public/javascripts/'
  HerokuDeployment::Config.commit_files << 'public/stylesheets/'
  # puts %(Running: \nRAILS_ENV=production ./script/rails runner "Rails.cache.clear; Rails.application.config.action_controller.perform_caching = false; require 'rails/console/app' ; app.get '#{HerokuDeployment::Config.generate_url}'")
  res = !!system(%(RAILS_ENV=production ./script/rails runner "Rails.cache.clear; Rails.application.config.action_controller.perform_caching = false; require 'rails/console/app' ; app.get '#{HerokuDeployment::Config.generate_url}'"))
  (js_files.collect{|j| "public/javascripts/#{j}"} + css_files.collect{|c| "public/stylesheets/#{c}"}).each do |f|
    unless File.exist?(f)
      puts "File '#{f}' did not get created! Deploy failed"
      return false
    end
  end
  res
end