Class: Kumade::Deployer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeployer

Returns a new instance of Deployer.


8
9
10
11
12
13
# File 'lib/kumade/deployer.rb', line 8

def initialize
  @git      = Git.new
  @heroku   = Heroku.new
  @branch   = @git.current_branch
  @packager = Packager.new(@git)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git


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

def git
  @git
end

#herokuObject (readonly)

Returns the value of attribute heroku


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

def heroku
  @heroku
end

#packagerObject (readonly)

Returns the value of attribute packager


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

def packager
  @packager
end

Instance Method Details

#deployObject


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kumade/deployer.rb', line 15

def deploy
  begin
    ensure_heroku_remote_exists
    pre_deploy
    heroku.sync
    heroku.migrate_database
  rescue => deploying_error
    Kumade.configuration.outputter.error("#{deploying_error.class}: #{deploying_error.message}")
  ensure
    post_deploy
  end
end

#ensure_clean_gitObject


46
47
48
# File 'lib/kumade/deployer.rb', line 46

def ensure_clean_git
  git.ensure_clean_git
end

#ensure_heroku_remote_existsObject


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/kumade/deployer.rb', line 50

def ensure_heroku_remote_exists
  if git.remote_exists?(Kumade.configuration.environment)
    if git.heroku_remote?
      Kumade.configuration.outputter.success("#{Kumade.configuration.environment} is a Heroku remote")
    else
      Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not point to Heroku})
    end
  else
    Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not exist})
  end
end

#package_assetsObject


34
35
36
# File 'lib/kumade/deployer.rb', line 34

def package_assets
  @packager.run
end

#post_deployObject


42
43
44
# File 'lib/kumade/deployer.rb', line 42

def post_deploy
  heroku.delete_deploy_branch
end

#pre_deployObject


28
29
30
31
32
# File 'lib/kumade/deployer.rb', line 28

def pre_deploy
  ensure_clean_git
  package_assets
  sync_origin
end

#sync_originObject


38
39
40
# File 'lib/kumade/deployer.rb', line 38

def sync_origin
  git.push(@branch)
end