Permalink
Browse files

Fixed capistrano recipes

  • Loading branch information...
1 parent ad3d087 commit 2be23d7c9e5993b8a16a83a206e58213bd13e821 @jferris jferris committed Jan 13, 2010
View
@@ -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']]
@@ -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|
View
@@ -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"
@@ -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)
@@ -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]}
@@ -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
@@ -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
View
@@ -1,24 +0,0 @@
-# When Hoptoad is installed as a plugin this is loaded automatically.
-#
-# When Hoptoad installed as a gem, you need to add
-# require 'hoptoad_notifier/recipes/hoptoad'
-# to your deploy.rb
-#
-# Defines deploy:notify_hoptoad which will send information about the deploy to Hoptoad.
-#
-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

1 comment on commit 2be23d7

Why has this file been removed? rake hoptoad:xxx no longer exist?

Please sign in to comment.