Skip to content

Commit

Permalink
Fixed capistrano recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 19, 2010
1 parent ad3d087 commit 2be23d7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 40 deletions.
5 changes: 2 additions & 3 deletions Rakefile
Expand Up @@ -41,8 +41,7 @@ gemspec = Gem::Specification.new do |s|
s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}

s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
'test/**/*.rb', 'rails/**/*.rb', 'recipes/**/*.rb',
'tasks/**/*.rake']
'test/**/*.rb', 'rails/**/*.rb', 'tasks/**/*.rake']
s.require_path = 'lib'
s.test_files = Dir[*['test/**/*_test.rb']]

Expand Down Expand Up @@ -73,7 +72,7 @@ task :gemspec do
end

LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
LOCAL_GEMS = %w(rails sham_rack)
LOCAL_GEMS = %w(rails sham_rack capistrano)

task :vendor_test_gems do
LOCAL_GEMS.each do |gem_name|
Expand Down
9 changes: 9 additions & 0 deletions features/rails.feature
Expand Up @@ -32,3 +32,12 @@ Feature: Install the Gem in a Rails application
And I configure my application to require the "hoptoad_notifier" gem
And I run "script/generate hoptoad"
Then I should see "Must pass --api-key or create config/initializers/hoptoad.rb"

Scenario: Configure and deploy
When I generate a new Rails application
And I run "capify ."
And I configure the Hoptoad shim
And I configure my application to require the "hoptoad_notifier" gem
And I run "script/generate hoptoad -k myapikey"
And I run "cap -T"
Then I should see "deploy:notify_hoptoad"
5 changes: 4 additions & 1 deletion features/support/terminal.rb
Expand Up @@ -30,8 +30,11 @@ def run(command)
def build_and_install_gem(gemspec)
pkg_dir = File.join(TEMP_DIR, 'pkg')
FileUtils.mkdir_p(pkg_dir)
`gem build #{gemspec} 2>&1`
output = `gem build #{gemspec} 2>&1`
gem_file = Dir.glob("*.gem").first
unless gem_file
raise "Gem didn't build:\n#{output}"
end
target = File.join(pkg_dir, gem_file)
FileUtils.mv(gem_file, target)
install_gem_to(BUILT_GEM_ROOT, target)
Expand Down
6 changes: 3 additions & 3 deletions generators/hoptoad/hoptoad_generator.rb
Expand Up @@ -14,9 +14,9 @@ def manifest
record do |m|
m.directory 'lib/tasks'
m.file 'hoptoad_notifier_tasks.rake', 'lib/tasks/hoptoad_notifier_tasks.rake'
# if File.exists?('config/deploy.rb')
# m.insert_into 'config/deploy.rb', "require 'hoptoad_notifier/recipes/hoptoad'"
# end
if File.exists?('config/deploy.rb')
m.append_to 'config/deploy.rb', "require 'hoptoad_notifier/capistrano'"
end
unless options[:api_key].nil?
m.template 'initializer.rb', 'config/initializers/hoptoad.rb',
:assigns => {:api_key => options[:api_key]}
Expand Down
19 changes: 10 additions & 9 deletions generators/hoptoad/lib/insert_commands.rb
Expand Up @@ -7,27 +7,28 @@ def file_contains?(relative_destination, line)
end

Rails::Generator::Commands::Create.class_eval do
def insert_into(file, line)
logger.insert "#{line} into #{file}"
def append_to(file, line)
logger.insert "#{line} appended to #{file}"
unless options[:pretend] || file_contains?(file, line)
gsub_file file, /^(class|module) .+$/ do |match|
"#{match}\n #{line}"
File.open(file, "a") do |file|
file.puts
file.puts line
end
end
end
end

Rails::Generator::Commands::Destroy.class_eval do
def insert_into(file, line)
logger.remove "#{line} from #{file}"
def append_to(file, line)
logger.remove "#{line} removed from #{file}"
unless options[:pretend]
gsub_file file, "\n #{line}", ''
gsub_file file, "\n#{line}", ''
end
end
end

Rails::Generator::Commands::List.class_eval do
def insert_into(file, line)
logger.insert "#{line} into #{file}"
def append_to(file, line)
logger.insert "#{line} appended to #{file}"
end
end
20 changes: 20 additions & 0 deletions lib/hoptoad_notifier/capistrano.rb
@@ -0,0 +1,20 @@
# Defines deploy:notify_hoptoad which will send information about the deploy to Hoptoad.

Capistrano::Configuration.instance(:must_exist).load do
after "deploy", "deploy:notify_hoptoad"
after "deploy:migrations", "deploy:notify_hoptoad"

namespace :deploy do
desc "Notify Hoptoad of the deployment"
task :notify_hoptoad, :except => { :no_release => true } do
rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
local_user = ENV['USER'] || ENV['USERNAME']
executable = RUBY_PLATFORM.downcase.include?('mswin') ? 'rake.bat' : 'rake'
notify_command = "#{executable} hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
puts "Notifying Hoptoad of Deploy (#{notify_command})"
`#{notify_command}`
puts "Hoptoad Notification Complete."
end
end
end
24 changes: 0 additions & 24 deletions recipes/hoptoad.rb

This file was deleted.

0 comments on commit 2be23d7

Please sign in to comment.