Class: Tol::Heroku

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

Instance Method Summary collapse

Instance Method Details

#deployObject



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
# File 'lib/tol/heroku.rb', line 16

def deploy
  puts Rainbow("Deploying to Heroku").foreground(:green)

  puts "Identifying git branch"
  branch = `git rev-parse --abbrev-ref HEAD`.gsub("\n", "")

  puts "Identified local branch #{Rainbow(branch).foreground(:green)}. Please confirm."
  choose do |menu|
    menu.prompt = "Continue?"
    
    menu.choice "Yes" do 
    end

    menu.choice "No" do
      return
    end
  end

  puts "Identifying Heroku application"
  apps = list_of_applications    
  if apps.length == 0
    puts Rainbow("No Heroku apps found").foreground(:red)
    puts "Add your remotes to .git/config"
    # TODO: Automatically add remotes
  elsif apps.length == 1
    deploy_to(apps[0], branch)
  else
    puts Rainbow("Multiple Heroku apps found").foreground(:green)

    choose do |menu|
      menu.prompt = "Where to deploy?"
      apps.each do |app|
        menu.choice app do
          deploy_to(app, branch)
        end
      end

      menu.choice "None"
    end
  end
end

#deploy_to(remote, branch) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/tol/heroku.rb', line 58

def deploy_to(remote, branch)
  Bundler.with_clean_env do
    system("git push -f #{remote} #{branch}:master")
    system("heroku run rake db:migrate --remote #{remote}")
    system("heroku restart --remote #{remote}")
  end
end

#list_of_applicationsObject



9
10
11
12
13
14
# File 'lib/tol/heroku.rb', line 9

def list_of_applications
  git_config = File.read(".git/config")
  git_config.scan(/heroku\..*:(.*)\.git/i).map do |result|
    result[0]
  end
end