hoptoad_notifier 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/INSTALL +25 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +221 -0
- data/Rakefile +117 -0
- data/SUPPORTED_RAILS_VERSIONS +8 -0
- data/TESTING.rdoc +8 -0
- data/generators/hoptoad/hoptoad_generator.rb +42 -0
- data/generators/hoptoad/lib/insert_commands.rb +34 -0
- data/generators/hoptoad/lib/rake_commands.rb +24 -0
- data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +5 -0
- data/generators/hoptoad/templates/initializer.rb +6 -0
- data/lib/hoptoad_notifier/backtrace.rb +99 -0
- data/lib/hoptoad_notifier/capistrano.rb +20 -0
- data/lib/hoptoad_notifier/catcher.rb +95 -0
- data/lib/hoptoad_notifier/configuration.rb +228 -0
- data/lib/hoptoad_notifier/notice.rb +295 -0
- data/lib/hoptoad_notifier/rails.rb +11 -0
- data/lib/hoptoad_notifier/rails_initializer.rb +16 -0
- data/lib/hoptoad_notifier/sender.rb +63 -0
- data/lib/hoptoad_notifier/tasks.rb +91 -0
- data/lib/hoptoad_notifier/version.rb +3 -0
- data/lib/hoptoad_notifier.rb +146 -0
- data/lib/hoptoad_tasks.rb +37 -0
- data/rails/init.rb +1 -0
- data/tasks/hoptoad_notifier_tasks.rake +89 -0
- data/test/backtrace_test.rb +118 -0
- data/test/catcher_test.rb +314 -0
- data/test/configuration_test.rb +207 -0
- data/test/helper.rb +237 -0
- data/test/hoptoad_tasks_test.rb +138 -0
- data/test/logger_test.rb +85 -0
- data/test/notice_test.rb +402 -0
- data/test/notifier_test.rb +222 -0
- data/test/rails_initializer_test.rb +35 -0
- data/test/sender_test.rb +123 -0
- metadata +99 -0
data/INSTALL
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
=== Configuration
|
2
|
+
|
3
|
+
You should have something like this in config/initializers/hoptoad.rb.
|
4
|
+
|
5
|
+
HoptoadNotifier.configure do |config|
|
6
|
+
config.api_key = '1234567890abcdef'
|
7
|
+
end
|
8
|
+
|
9
|
+
(Please note that this configuration should be in a global configuration, and
|
10
|
+
is *not* environment-specific. Hoptoad is smart enough to know what errors are
|
11
|
+
caused by what environments, so your staging errors don't get mixed in with
|
12
|
+
your production errors.)
|
13
|
+
|
14
|
+
You can test that Hoptoad is working in your production environment by using
|
15
|
+
this rake task (from RAILS_ROOT):
|
16
|
+
|
17
|
+
rake hoptoad:test
|
18
|
+
|
19
|
+
If everything is configured properly, that task will send a notice to Hoptoad
|
20
|
+
which will be visible immediately.
|
21
|
+
|
22
|
+
NOTE FOR RAILS 1.2.* USERS:
|
23
|
+
|
24
|
+
You will need to copy the hoptoad_notifier_tasks.rake file into your
|
25
|
+
RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
= HoptoadNotifier
|
2
|
+
|
3
|
+
This is the notifier gem for integrating apps with Hoptoad.
|
4
|
+
|
5
|
+
When an uncaught exception occurs, HoptoadNotifier will POST the relevant data
|
6
|
+
to the Hoptoad server specified in your environment.
|
7
|
+
|
8
|
+
== Help
|
9
|
+
|
10
|
+
* {IRC}[irc://irc.freenode.net/thoughtbot]
|
11
|
+
* {mailing list}[http://groups.google.com/group/hoptoad-notifier-dev]
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
=== Remove exception_notifier
|
16
|
+
|
17
|
+
in your ApplicationController, REMOVE this line:
|
18
|
+
|
19
|
+
include ExceptionNotifiable
|
20
|
+
|
21
|
+
In your config/environment* files, remove all references to ExceptionNotifier
|
22
|
+
|
23
|
+
Remove the vendor/plugins/exception_notifier directory.
|
24
|
+
|
25
|
+
=== Rails 2.x
|
26
|
+
|
27
|
+
Add the hoptoad_notifier gem to your app. In config/environment.rb:
|
28
|
+
|
29
|
+
config.gem 'hoptoad_notifier'
|
30
|
+
|
31
|
+
Then from your project's RAILS_ROOT, run:
|
32
|
+
|
33
|
+
rake gems:install
|
34
|
+
script/generate hoptoad --api-key your_key_here
|
35
|
+
|
36
|
+
=== Rails 1.2.6
|
37
|
+
|
38
|
+
Install the hoptoad_notifier Gem, and then add something like this at the
|
39
|
+
bottom of your config/environment.rb:
|
40
|
+
|
41
|
+
HoptoadNotifier.configure do |config|
|
42
|
+
config.api_key = 'your_key_here'
|
43
|
+
end
|
44
|
+
|
45
|
+
You will need to copy the hoptoad_notifier_tasks.rake file into your
|
46
|
+
RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work.
|
47
|
+
|
48
|
+
=== Testing it out
|
49
|
+
|
50
|
+
You can test that Hoptoad is working in your production environment by using
|
51
|
+
this rake task (from RAILS_ROOT):
|
52
|
+
|
53
|
+
rake hoptoad:test
|
54
|
+
|
55
|
+
If everything is configured properly, that task will send a notice to Hoptoad
|
56
|
+
which will be visible immediately.
|
57
|
+
|
58
|
+
== Usage
|
59
|
+
|
60
|
+
For the most part, Hoptoad works for itself. Once you've included the notifier
|
61
|
+
in your ApplicationController (which is now done automatically by the gem),
|
62
|
+
all errors will be rescued by the #rescue_action_in_public provided by the gem.
|
63
|
+
|
64
|
+
If you want to log arbitrary things which you've rescued yourself from a
|
65
|
+
controller, you can do something like this:
|
66
|
+
|
67
|
+
...
|
68
|
+
rescue => ex
|
69
|
+
notify_hoptoad(ex)
|
70
|
+
flash[:failure] = 'Encryptions could not be rerouted, try again.'
|
71
|
+
end
|
72
|
+
...
|
73
|
+
|
74
|
+
The #notify_hoptoad call will send the notice over to Hoptoad for later
|
75
|
+
analysis. While in your controllers you use the notify_hoptoad method, anywhere
|
76
|
+
else in your code, use HoptoadNotifier.notify.
|
77
|
+
|
78
|
+
To perform custom error processing after Hoptoad has been notified, define the
|
79
|
+
instance method #rescue_action_in_public_without_hoptoad(exception) in your
|
80
|
+
controller.
|
81
|
+
|
82
|
+
== Tracking deployments in Hoptoad
|
83
|
+
|
84
|
+
Paying Hoptoad plans support the ability to track deployments of your application in Hoptoad.
|
85
|
+
By notifying Hoptoad of your application deployments, all errors are resolved when a deploy occurs,
|
86
|
+
so that you'll be notified again about any errors that reoccur after a deployment.
|
87
|
+
|
88
|
+
Additionally, it's possible to review the errors in Hoptoad that occurred before and after a deploy.
|
89
|
+
|
90
|
+
When Hoptoad is installed as a gem, you need to add
|
91
|
+
|
92
|
+
require 'hoptoad_notifier/recipes/hoptoad'
|
93
|
+
|
94
|
+
to your deploy.rb
|
95
|
+
|
96
|
+
== Going beyond exceptions
|
97
|
+
|
98
|
+
You can also pass a hash to notify_hoptoad method and store whatever you want,
|
99
|
+
not just an exception. And you can also use it anywhere, not just in
|
100
|
+
controllers:
|
101
|
+
|
102
|
+
begin
|
103
|
+
params = {
|
104
|
+
# params that you pass to a method that can throw an exception
|
105
|
+
}
|
106
|
+
my_unpredicable_method(params)
|
107
|
+
rescue => e
|
108
|
+
HoptoadNotifier.notify(
|
109
|
+
:error_class => "Special Error",
|
110
|
+
:error_message => "Special Error: #{e.message}",
|
111
|
+
:parameters => params
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
While in your controllers you use the notify_hoptoad method, anywhere else in
|
116
|
+
your code, use HoptoadNotifier.notify. Hoptoad will get all the information
|
117
|
+
about the error itself. As for a hash, these are the keys you should pass:
|
118
|
+
|
119
|
+
* :error_class - Use this to group similar errors together. When Hoptoad catches an exception it sends the class name of that exception object.
|
120
|
+
* :error_message - This is the title of the error you see in the errors list. For exceptions it is "#{exception.class.name}: #{exception.message}"
|
121
|
+
* :parameters - While there are several ways to send additional data to Hoptoad, passing a Hash as :parameters as in the example above is the most common use case. When Hoptoad catches an exception in a controller, the actual HTTP client request parameters are sent using this key.
|
122
|
+
|
123
|
+
Hoptoad merges the hash you pass with these default options:
|
124
|
+
|
125
|
+
{
|
126
|
+
:api_key => HoptoadNotifier.api_key,
|
127
|
+
:error_message => 'Notification',
|
128
|
+
:backtrace => caller,
|
129
|
+
:parameters => {},
|
130
|
+
:session => {}
|
131
|
+
}
|
132
|
+
|
133
|
+
You can override any of those parameters.
|
134
|
+
|
135
|
+
== Filtering
|
136
|
+
|
137
|
+
You can specify a whitelist of errors, that Hoptoad will not report on. Use
|
138
|
+
this feature when you are so apathetic to certain errors that you don't want
|
139
|
+
them even logged.
|
140
|
+
|
141
|
+
This filter will only be applied to automatic notifications, not manual
|
142
|
+
notifications (when #notify is called directly).
|
143
|
+
|
144
|
+
Hoptoad ignores the following exceptions by default:
|
145
|
+
|
146
|
+
ActiveRecord::RecordNotFound
|
147
|
+
ActionController::RoutingError
|
148
|
+
ActionController::InvalidAuthenticityToken
|
149
|
+
ActionController::UnknownAction
|
150
|
+
CGI::Session::CookieStore::TamperedWithCookie
|
151
|
+
|
152
|
+
To ignore errors in addition to those, specify their names in your Hoptoad
|
153
|
+
configuration block.
|
154
|
+
|
155
|
+
HoptoadNotifier.configure do |config|
|
156
|
+
config.api_key = '1234567890abcdef'
|
157
|
+
config.ignore << ActiveRecord::IgnoreThisError
|
158
|
+
end
|
159
|
+
|
160
|
+
To ignore *only* certain errors (and override the defaults), use the
|
161
|
+
#ignore_only attribute.
|
162
|
+
|
163
|
+
HoptoadNotifier.configure do |config|
|
164
|
+
config.api_key = '1234567890abcdef'
|
165
|
+
config.ignore_only = [ActiveRecord::IgnoreThisError]
|
166
|
+
end
|
167
|
+
|
168
|
+
To ignore certain user agents, add in the #ignore_user_agent attribute as a
|
169
|
+
string or regexp:
|
170
|
+
|
171
|
+
HoptoadNotifier.configure do |config|
|
172
|
+
config.api_key = '1234567890abcdef'
|
173
|
+
config.ignore_user_agent << /Ignored/
|
174
|
+
config.ignore_user_agent << 'IgnoredUserAgent'
|
175
|
+
end
|
176
|
+
|
177
|
+
To ignore exceptions based on other conditions, use #ignore_by_filter:
|
178
|
+
|
179
|
+
HoptoadNotifier.configure do |config|
|
180
|
+
config.api_key = '1234567890abcdef'
|
181
|
+
config.ignore_by_filter do |exception_data|
|
182
|
+
true if exception_data[:error_class] == "RuntimeError"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
To replace sensitive information sent to the Hoptoad service with [FILTERED] use #params_filters:
|
187
|
+
|
188
|
+
HoptoadNotifier.configure do |config|
|
189
|
+
config.api_key = '1234567890abcdef'
|
190
|
+
config.params_filters << "credit_card_number"
|
191
|
+
end
|
192
|
+
|
193
|
+
Note that, when rescuing exceptions within an ActionController method,
|
194
|
+
hoptoad_notifier will reuse filters specified by #filter_params_logging.
|
195
|
+
|
196
|
+
== Testing
|
197
|
+
|
198
|
+
When you run your tests, you might notice that the Hoptoad service is recording
|
199
|
+
notices generated using #notify when you don't expect it to. You can
|
200
|
+
use code like this in your test_helper.rb to redefine that method so those
|
201
|
+
errors are not reported while running tests.
|
202
|
+
|
203
|
+
module HoptoadNotifier
|
204
|
+
def self.notify(thing)
|
205
|
+
# do nothing.
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
== Supported Rails versions
|
210
|
+
|
211
|
+
See SUPPORTED_RAILS_VERSIONS for a list of official supported versions of
|
212
|
+
Rails.
|
213
|
+
|
214
|
+
Please open up a support ticket on Tender ( http://help.hoptoadapp.com ) if
|
215
|
+
you're using a version of Rails that is not listed above and the notifier is
|
216
|
+
not working properly.
|
217
|
+
|
218
|
+
== Thanks
|
219
|
+
|
220
|
+
Thanks to Eugene Bolshakov for the excellent write-up on GOING BEYOND
|
221
|
+
EXCEPTIONS, which we have included above.
|
data/Rakefile
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
desc 'Default: run unit tests.'
|
8
|
+
task :default => [:test, :cucumber]
|
9
|
+
|
10
|
+
desc 'Test the hoptoad_notifier gem.'
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.libs << 'lib'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run ginger tests'
|
18
|
+
task :ginger do
|
19
|
+
$LOAD_PATH << File.join(*%w[vendor ginger lib])
|
20
|
+
ARGV.clear
|
21
|
+
ARGV << 'test'
|
22
|
+
load File.join(*%w[vendor ginger bin ginger])
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'yard'
|
27
|
+
YARD::Rake::YardocTask.new do |t|
|
28
|
+
t.files = ['lib/**/*.rb', 'TESTING.rdoc']
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
end
|
32
|
+
|
33
|
+
GEM_ROOT = File.dirname(__FILE__).freeze
|
34
|
+
VERSION_FILE = File.join(GEM_ROOT, 'lib', 'hoptoad_notifier', 'version')
|
35
|
+
|
36
|
+
require VERSION_FILE
|
37
|
+
|
38
|
+
gemspec = Gem::Specification.new do |s|
|
39
|
+
s.name = %q{hoptoad_notifier}
|
40
|
+
s.version = HoptoadNotifier::VERSION
|
41
|
+
s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}
|
42
|
+
|
43
|
+
s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
|
44
|
+
'test/**/*.rb', 'rails/**/*.rb', 'tasks/**/*.rake']
|
45
|
+
s.require_path = 'lib'
|
46
|
+
s.test_files = Dir[*['test/**/*_test.rb']]
|
47
|
+
|
48
|
+
s.has_rdoc = true
|
49
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
50
|
+
s.rdoc_options = ['--line-numbers', "--main", "README.rdoc"]
|
51
|
+
|
52
|
+
s.authors = ["thoughtbot, inc"]
|
53
|
+
s.email = %q{support@hoptoadapp.com}
|
54
|
+
s.homepage = "http://www.hoptoadapp.com"
|
55
|
+
|
56
|
+
s.platform = Gem::Platform::RUBY
|
57
|
+
end
|
58
|
+
|
59
|
+
Rake::GemPackageTask.new gemspec do |pkg|
|
60
|
+
pkg.need_tar = true
|
61
|
+
pkg.need_zip = true
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Clean files generated by rake tasks"
|
65
|
+
task :clobber => [:clobber_rdoc, :clobber_package]
|
66
|
+
|
67
|
+
desc "Generate a gemspec file"
|
68
|
+
task :gemspec do
|
69
|
+
File.open("#{gemspec.name}.gemspec", 'w') do |f|
|
70
|
+
f.write gemspec.to_ruby
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
|
75
|
+
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
|
76
|
+
LOCAL_GEMS = [['sham_rack', nil], ['capistrano', nil], ['sqlite3-ruby', nil]] +
|
77
|
+
RAILS_VERSIONS.collect { |version| ['rails', version] }
|
78
|
+
|
79
|
+
task :vendor_test_gems do
|
80
|
+
LOCAL_GEMS.each do |gem_name, version|
|
81
|
+
gem_file_pattern = [gem_name, version || '*'].compact.join('-')
|
82
|
+
version_option = version ? "-v #{version}" : ''
|
83
|
+
pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
|
84
|
+
existing = Dir.glob(pattern).first
|
85
|
+
unless existing
|
86
|
+
command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc #{version_option} #{gem_name}"
|
87
|
+
puts "Vendoring #{gem_file_pattern}..."
|
88
|
+
unless system(command)
|
89
|
+
$stderr.puts "Command failed: #{command}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
96
|
+
t.fork = true
|
97
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
98
|
+
end
|
99
|
+
|
100
|
+
task :cucumber => [:gemspec, :vendor_test_gems]
|
101
|
+
|
102
|
+
OLD_RAILS_VERSIONS = RAILS_VERSIONS[0...-1]
|
103
|
+
|
104
|
+
namespace :cucumber do
|
105
|
+
namespace :rails do
|
106
|
+
OLD_RAILS_VERSIONS.each do |version|
|
107
|
+
desc "Test integration of the gem with Rails #{version}"
|
108
|
+
task version do
|
109
|
+
ENV['RAILS_VERSION'] = version
|
110
|
+
system("cucumber --format progress features/rails.feature")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "Test integration of the gem with all Rails versions"
|
115
|
+
task :all => [:cucumber, *OLD_RAILS_VERSIONS]
|
116
|
+
end
|
117
|
+
end
|
data/TESTING.rdoc
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
= For Maintainers:
|
2
|
+
|
3
|
+
When developing the Hoptoad Notifier, be sure to use the integration test
|
4
|
+
against an existing project on staging before pushing to master.
|
5
|
+
|
6
|
+
+./script/integration_test.rb <test project's api key> <staging server hostname>+
|
7
|
+
|
8
|
+
+./script/integration_test.rb <test project's api key> <staging server hostname> secure+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
|
3
|
+
|
4
|
+
class HoptoadGenerator < Rails::Generator::Base
|
5
|
+
def add_options!(opt)
|
6
|
+
opt.on('-k', '--api-key=key', String, "Your Hoptoad API key") {|v| options[:api_key] = v}
|
7
|
+
end
|
8
|
+
|
9
|
+
def manifest
|
10
|
+
if !api_key_configured? && !options[:api_key]
|
11
|
+
puts "Must pass --api-key or create config/initializers/hoptoad.rb"
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
record do |m|
|
15
|
+
m.directory 'lib/tasks'
|
16
|
+
m.file 'hoptoad_notifier_tasks.rake', 'lib/tasks/hoptoad_notifier_tasks.rake'
|
17
|
+
if File.exists?('config/deploy.rb')
|
18
|
+
m.append_to 'config/deploy.rb', "require 'hoptoad_notifier/capistrano'"
|
19
|
+
end
|
20
|
+
if options[:api_key]
|
21
|
+
if use_initializer?
|
22
|
+
m.template 'initializer.rb', 'config/initializers/hoptoad.rb',
|
23
|
+
:assigns => {:api_key => options[:api_key]}
|
24
|
+
else
|
25
|
+
m.template 'initializer.rb', 'config/hoptoad.rb',
|
26
|
+
:assigns => {:api_key => options[:api_key]}
|
27
|
+
m.append_to 'config/environment.rb', "require 'config/hoptoad'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
m.rake "hoptoad:test", :generate_only => true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def use_initializer?
|
35
|
+
Rails::VERSION::MAJOR > 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def api_key_configured?
|
39
|
+
File.exists?('config/initializers/hoptoad.rb') ||
|
40
|
+
system("grep HoptoadNotifier config/environment.rb")
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
def append_to(file, line)
|
11
|
+
logger.insert "#{line} appended to #{file}"
|
12
|
+
unless options[:pretend] || file_contains?(file, line)
|
13
|
+
File.open(file, "a") do |file|
|
14
|
+
file.puts
|
15
|
+
file.puts line
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
22
|
+
def append_to(file, line)
|
23
|
+
logger.remove "#{line} removed from #{file}"
|
24
|
+
unless options[:pretend]
|
25
|
+
gsub_file file, "\n#{line}", ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails::Generator::Commands::List.class_eval do
|
31
|
+
def append_to(file, line)
|
32
|
+
logger.insert "#{line} appended to #{file}"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def rake(cmd, opts = {})
|
3
|
+
logger.rake "rake #{cmd}"
|
4
|
+
unless system("rake #{cmd}")
|
5
|
+
logger.rake "#{cmd} failed. Rolling back"
|
6
|
+
command(:destroy).invoke!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
12
|
+
def rake(cmd, opts = {})
|
13
|
+
unless opts[:generate_only]
|
14
|
+
logger.rake "rake #{cmd}"
|
15
|
+
system "rake #{cmd}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rails::Generator::Commands::List.class_eval do
|
21
|
+
def rake(cmd, opts = {})
|
22
|
+
logger.rake "rake #{cmd}"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module HoptoadNotifier
|
2
|
+
# Front end to parsing the backtrace for each notice
|
3
|
+
class Backtrace
|
4
|
+
|
5
|
+
# Handles backtrace parsing line by line
|
6
|
+
class Line
|
7
|
+
|
8
|
+
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
|
9
|
+
|
10
|
+
# The file portion of the line (such as app/models/user.rb)
|
11
|
+
attr_reader :file
|
12
|
+
|
13
|
+
# The line number portion of the line
|
14
|
+
attr_reader :number
|
15
|
+
|
16
|
+
# The method of the line (such as index)
|
17
|
+
attr_reader :method
|
18
|
+
|
19
|
+
# Parses a single line of a given backtrace
|
20
|
+
# @param [String] unparsed_line The raw line from +caller+ or some backtrace
|
21
|
+
# @return [Line] The parsed backtrace line
|
22
|
+
def self.parse(unparsed_line)
|
23
|
+
_, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a
|
24
|
+
new(file, number, method)
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(file, number, method)
|
28
|
+
self.file = file
|
29
|
+
self.number = number
|
30
|
+
self.method = method
|
31
|
+
end
|
32
|
+
|
33
|
+
# Reconstructs the line in a readable fashion
|
34
|
+
def to_s
|
35
|
+
"#{file}:#{number}:in `#{method}'"
|
36
|
+
end
|
37
|
+
|
38
|
+
def ==(other)
|
39
|
+
to_s == other.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
def inspect
|
43
|
+
"<Line:#{to_s}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_writer :file, :number, :method
|
49
|
+
end
|
50
|
+
|
51
|
+
# holder for an Array of Backtrace::Line instances
|
52
|
+
attr_reader :lines
|
53
|
+
|
54
|
+
def self.parse(ruby_backtrace, opts = {})
|
55
|
+
ruby_lines = split_multiline_backtrace(ruby_backtrace)
|
56
|
+
|
57
|
+
filters = opts[:filters] || []
|
58
|
+
filtered_lines = ruby_lines.to_a.map do |line|
|
59
|
+
filters.inject(line) do |line, proc|
|
60
|
+
proc.call(line)
|
61
|
+
end
|
62
|
+
end.compact
|
63
|
+
|
64
|
+
lines = filtered_lines.collect do |unparsed_line|
|
65
|
+
Line.parse(unparsed_line)
|
66
|
+
end
|
67
|
+
|
68
|
+
instance = new(lines)
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize(lines)
|
72
|
+
self.lines = lines
|
73
|
+
end
|
74
|
+
|
75
|
+
def inspect
|
76
|
+
"<Backtrace: " + lines.collect { |line| line.inspect }.join(", ") + ">"
|
77
|
+
end
|
78
|
+
|
79
|
+
def ==(other)
|
80
|
+
if other.respond_to?(:lines)
|
81
|
+
lines == other.lines
|
82
|
+
else
|
83
|
+
false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
attr_writer :lines
|
90
|
+
|
91
|
+
def self.split_multiline_backtrace(backtrace)
|
92
|
+
if backtrace.to_a.size == 1
|
93
|
+
backtrace.to_a.first.split(/\n\s*/)
|
94
|
+
else
|
95
|
+
backtrace
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Defines deploy:notify_hoptoad which will send information about the deploy to Hoptoad.
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
after "deploy", "deploy:notify_hoptoad"
|
5
|
+
after "deploy:migrations", "deploy:notify_hoptoad"
|
6
|
+
|
7
|
+
namespace :deploy do
|
8
|
+
desc "Notify Hoptoad of the deployment"
|
9
|
+
task :notify_hoptoad, :except => { :no_release => true } do
|
10
|
+
rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
|
11
|
+
local_user = ENV['USER'] || ENV['USERNAME']
|
12
|
+
executable = RUBY_PLATFORM.downcase.include?('mswin') ? 'rake.bat' : 'rake'
|
13
|
+
notify_command = "#{executable} hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
|
14
|
+
notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
|
15
|
+
puts "Notifying Hoptoad of Deploy (#{notify_command})"
|
16
|
+
`#{notify_command}`
|
17
|
+
puts "Hoptoad Notification Complete."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|