Class: DeploymentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/deployment/deployment_generator.rb

Instance Method Summary collapse

Instance Method Details

#inject_new_deployment_to_stagesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/deployment/deployment_generator.rb', line 16

def inject_new_deployment_to_stages
  new_contents = ""
  File.new(Rails.root.join('config','deploy.rb')).readlines.each do |line|
    unless line =~ /^set :stages, (.*)$/
      new_contents << line
    else
      stages = eval($1)
      stages << name
      stages.uniq!
      stage_array_contents = stages.map{|stage| "\"#{stage}\""}.join(', ')
      new_contents << "set :stages, [#{stage_array_contents}]\n"
    end
  end
  File.open(Rails.root.join('config','deploy.rb'),'w') do |file|
    file.write new_contents
  end
end

#write_stage_fileObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/generators/deployment/deployment_generator.rb', line 5

def write_stage_file
  create_file "config/deploy/#{name}.rb", <<-DEPLOY_STAGE
set :user, 'deploy'
set :use_sudo, false

role :web, "#{hostname}"
role :app, "#{hostname}"
role :db,  "#{hostname}", :primary => true
  DEPLOY_STAGE
end