Skip to content

Instantly share code, notes, and snippets.

@jackjennings
Created April 24, 2015 23:15
Show Gist options
  • Save jackjennings/4276f4c5ceaff52ac547 to your computer and use it in GitHub Desktop.
Save jackjennings/4276f4c5ceaff52ac547 to your computer and use it in GitHub Desktop.
def cap_install!
log :capify, ""
in_root do
run("#{extify(:cap)} install", verbose: false)
end
end
def include_cap_modules(cap_modules)
escaped_modules = cap_modules.map(&Regexp.method(:escape))
matcher = /require 'capistrano\/(#{escaped_modules.join('|')})'/
uncomment_lines 'Capfile', matcher
end
CAP_MODULES = %w[rvm bundler rails/assets rails/migrations passenger]
CAP_GEMS = CAP_MODULES.map {|m| "capistrano-#{m.split('/').first}" }.uniq
CAP_LINKED_FILES = %w[.ruby-env]
gem_group :development do
gem 'capistrano'
CAP_GEMS.each do |cap_gem|
gem cap_gem
end
end
after_bundle do
cap_install!
include_cap_modules CAP_MODULES
'config/deploy.rb'.tap do |deploy|
gsub_file deploy, 'my_app_name', @app_name
gsub_file deploy, /set :repo_url.*\n/, "set :repo_url, '[email protected]:noeassociates/#{@app_name}.git'\n"
uncomment_lines deploy, /set :linked_(dirs|files)/
gsub_file deploy,
/(set :linked_files.*push\().*(\))\n/,
'\1' + CAP_LINKED_FILES.map(&:inspect).join(', ') + '\2' + "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment