Class: Kumade::Heroku

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

Constant Summary collapse

DEPLOY_BRANCH =
"deploy"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeroku

Returns a new instance of Heroku.



8
9
10
11
# File 'lib/kumade/heroku.rb', line 8

def initialize
  @git    = Git.new
  @branch = @git.current_branch
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



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

def git
  @git
end

Instance Method Details

#cedar?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
# File 'lib/kumade/heroku.rb', line 41

def cedar?
  return @cedar unless @cedar.nil?

  command_line = CommandLine.new("bundle exec heroku stack --remote #{Kumade.configuration.environment}")

  @cedar = command_line.run_or_error.split("\n").grep(/\*/).any? do |line|
    line.include?("cedar")
  end
end

#delete_deploy_branchObject



31
32
33
# File 'lib/kumade/heroku.rb', line 31

def delete_deploy_branch
  git.delete(DEPLOY_BRANCH, @branch)
end

#heroku(command) ⇒ Object



35
36
37
38
39
# File 'lib/kumade/heroku.rb', line 35

def heroku(command)
  full_heroku_command = "#{bundle_exec_heroku} #{command} --remote #{Kumade.configuration.environment}"
  command_line = CommandLine.new(full_heroku_command)
  command_line.run_or_error("Failed to run #{command} on Heroku")
end

#migrate_databaseObject



18
19
20
21
# File 'lib/kumade/heroku.rb', line 18

def migrate_database
  heroku("rake db:migrate") unless Kumade.configuration.pretending?
  Kumade.configuration.outputter.success("Migrated #{Kumade.configuration.environment}")
end

#restart_appObject



23
24
25
26
27
28
29
# File 'lib/kumade/heroku.rb', line 23

def restart_app
  unless Kumade.configuration.pretending?
    command_line = CommandLine.new("bundle exec heroku restart --remote #{Kumade.configuration.environment}")
    command_line.run_or_error("Failed to restart #{Kumade.configuration.environment}")
  end
  Kumade.configuration.outputter.success("Restarted #{Kumade.configuration.environment}")
end

#syncObject



13
14
15
16
# File 'lib/kumade/heroku.rb', line 13

def sync
  git.create(DEPLOY_BRANCH)
  git.push("#{DEPLOY_BRANCH}:master", Kumade.configuration.environment, true)
end