square-hoptoad_notifier 2.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/CHANGELOG +427 -0
  2. data/INSTALL +25 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.md +435 -0
  5. data/README_FOR_HEROKU_ADDON.md +93 -0
  6. data/Rakefile +227 -0
  7. data/SUPPORTED_RAILS_VERSIONS +10 -0
  8. data/TESTING.rdoc +8 -0
  9. data/generators/hoptoad/hoptoad_generator.rb +88 -0
  10. data/generators/hoptoad/lib/insert_commands.rb +34 -0
  11. data/generators/hoptoad/lib/rake_commands.rb +24 -0
  12. data/generators/hoptoad/templates/capistrano_hook.rb +6 -0
  13. data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +25 -0
  14. data/generators/hoptoad/templates/initializer.rb +6 -0
  15. data/lib/hoptoad_notifier.rb +153 -0
  16. data/lib/hoptoad_notifier/backtrace.rb +99 -0
  17. data/lib/hoptoad_notifier/capistrano.rb +20 -0
  18. data/lib/hoptoad_notifier/configuration.rb +242 -0
  19. data/lib/hoptoad_notifier/notice.rb +337 -0
  20. data/lib/hoptoad_notifier/rack.rb +42 -0
  21. data/lib/hoptoad_notifier/rails.rb +41 -0
  22. data/lib/hoptoad_notifier/rails/action_controller_catcher.rb +30 -0
  23. data/lib/hoptoad_notifier/rails/controller_methods.rb +68 -0
  24. data/lib/hoptoad_notifier/rails/error_lookup.rb +33 -0
  25. data/lib/hoptoad_notifier/rails/javascript_notifier.rb +42 -0
  26. data/lib/hoptoad_notifier/rails3_tasks.rb +82 -0
  27. data/lib/hoptoad_notifier/railtie.rb +32 -0
  28. data/lib/hoptoad_notifier/sender.rb +83 -0
  29. data/lib/hoptoad_notifier/shared_tasks.rb +29 -0
  30. data/lib/hoptoad_notifier/tasks.rb +83 -0
  31. data/lib/hoptoad_notifier/user_informer.rb +23 -0
  32. data/lib/hoptoad_notifier/version.rb +3 -0
  33. data/lib/hoptoad_tasks.rb +44 -0
  34. data/lib/rails/generators/hoptoad/hoptoad_generator.rb +94 -0
  35. data/lib/templates/javascript_notifier.erb +13 -0
  36. data/lib/templates/rescue.erb +91 -0
  37. data/rails/init.rb +1 -0
  38. data/script/integration_test.rb +38 -0
  39. data/test/backtrace_test.rb +118 -0
  40. data/test/catcher_test.rb +331 -0
  41. data/test/configuration_test.rb +216 -0
  42. data/test/helper.rb +248 -0
  43. data/test/hoptoad_tasks_test.rb +152 -0
  44. data/test/javascript_notifier_test.rb +52 -0
  45. data/test/logger_test.rb +85 -0
  46. data/test/notice_test.rb +448 -0
  47. data/test/notifier_test.rb +222 -0
  48. data/test/rack_test.rb +58 -0
  49. data/test/rails_initializer_test.rb +36 -0
  50. data/test/sender_test.rb +161 -0
  51. data/test/user_informer_test.rb +29 -0
  52. metadata +225 -0
@@ -0,0 +1,93 @@
1
+ Hoptoad
2
+ ===========
3
+ Send your application errors to our hosted service and reclaim your inbox.
4
+
5
+ 1. Installing the Heroku add-on
6
+ ----------------------------
7
+ To use Hoptoad on Heroku, install the Hoptoad add-on:
8
+
9
+ $ heroku addons:add hoptoad:basic # This adds the the basic plan.
10
+ # If you'd like another plan, specify that instead.
11
+
12
+ 2. Including the Hoptoad notifier in your application
13
+ --------------------------------------------------
14
+ After adding the Hoptoad add-on, you will need to install and configure the Hoptoad notifier.
15
+
16
+ Your application connects to Hoptoad with an API key. On Heroku, this is automatically provided to your
17
+ application in `ENV['HOPTOAD_API_KEY']`, so installation should be a snap!
18
+
19
+ ### Rails 3.x
20
+
21
+ Add the hoptoad_notifier and heroku gems to your Gemfile. In Gemfile:
22
+
23
+ gem 'hoptoad_notifier'
24
+ gem 'heroku'
25
+
26
+ Then from your project's RAILS_ROOT, run:
27
+
28
+ $ bundle install
29
+ $ script/rails generate hoptoad --heroku
30
+
31
+ ### Rails 2.x
32
+
33
+ Install the heroku gem if you haven't already:
34
+
35
+ gem install heroku
36
+
37
+ Add the hoptoad_notifier gem to your app. In config/environment.rb:
38
+
39
+ config.gem 'hoptoad_notifier'
40
+
41
+ Then from your project's RAILS_ROOT, run:
42
+
43
+ $ rake gems:install
44
+ $ rake gems:unpack GEM=hoptoad_notifier
45
+ $ script/generate hoptoad --heroku
46
+
47
+ As always, if you choose not to vendor the hoptoad_notifier gem, make sure
48
+ every server you deploy to has the gem installed or your application won't start.
49
+
50
+ ### Rack applications
51
+
52
+ In order to use hoptoad_notifier in a non-Rails rack app, just load the hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack middleware:
53
+
54
+ require 'rubygems'
55
+ require 'rack'
56
+ require 'hoptoad_notifier'
57
+
58
+ HoptoadNotifier.configure do |config|
59
+ config.api_key = `ENV['HOPTOAD_API_KEY']`
60
+ end
61
+
62
+ app = Rack::Builder.app do
63
+ use HoptoadNotifier::Rack
64
+ run lambda { |env| raise "Rack down" }
65
+ end
66
+
67
+ ### Rails 1.x
68
+
69
+ For Rails 1.x, visit the [Hoptoad notifier's README on GitHub](http://github.com/thoughtbot/hoptoad_notifier),
70
+ and be sure to use `ENV['HOPTOAD_API_KEY']` where your API key is required in configuration code.
71
+
72
+ 3. Configure your notification settings (important!)
73
+ ---------------------------------------------------
74
+
75
+ Once you have included and configured the notifier in your application,
76
+ you will want to configure your notification settings.
77
+
78
+ This is important - without setting your email address, you won't receive notification emails.
79
+
80
+ Hoptoad can deliver exception notifications to your email inbox. To configure these delivery settings:
81
+
82
+ 1. Visit your application's Hoptoad Add-on page, like [ http://api.heroku.com/myapps/my-great-app/addons/hoptoad:basic ](http://api.heroku.com/myapps/my-great-app/addons/hoptoad:basic)
83
+ 2. Click "Go to Hoptoad admin" to configure the Hoptoad Add-on on the Hoptoadapp.com website
84
+ 3. Click the "Profile" button in the header to edit your email address and notification settings.
85
+
86
+ 4. Optionally: Set up deploy notification
87
+ -----------------------------------------
88
+
89
+ If your Hoptoad plan supports deploy notification, set it up for your Heroku application like this:
90
+
91
+ rake hoptoad:heroku:add_deploy_notification
92
+
93
+ This will install a Heroku [HTTP Deploy Hook](http://docs.heroku.com/deploy-hooks) to notify Hoptoad of the deploy.
data/Rakefile ADDED
@@ -0,0 +1,227 @@
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:rails:all"]
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
+ namespace :changeling do
26
+ desc "Bumps the version by a minor or patch version, depending on what was passed in."
27
+ task :bump, :part do |t, args|
28
+ # Thanks, Jeweler!
29
+ if HoptoadNotifier::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
30
+ major = $1.to_i
31
+ minor = $2.to_i
32
+ patch = $3.to_i
33
+ build = $4
34
+ else
35
+ abort
36
+ end
37
+
38
+ case args[:part]
39
+ when /minor/
40
+ minor += 1
41
+ patch = 0
42
+ when /patch/
43
+ patch += 1
44
+ else
45
+ abort
46
+ end
47
+
48
+ version = [major, minor, patch, build].compact.join('.')
49
+
50
+ File.open(File.join("lib", "hoptoad_notifier", "version.rb"), "w") do |f|
51
+ f.write <<EOF
52
+ module HoptoadNotifier
53
+ VERSION = "#{version}".freeze
54
+ end
55
+ EOF
56
+ end
57
+ end
58
+
59
+ desc "Writes out the new CHANGELOG and prepares the release"
60
+ task :change do
61
+ load 'lib/hoptoad_notifier/version.rb'
62
+ file = "CHANGELOG"
63
+ old = File.read(file)
64
+ version = HoptoadNotifier::VERSION
65
+ message = "Bumping to version #{version}"
66
+
67
+ File.open(file, "w") do |f|
68
+ f.write <<EOF
69
+ Version #{version} - #{Time.now}
70
+ ===============================================================================
71
+
72
+ #{`git log $(git tag | tail -1)..HEAD | git shortlog`}
73
+ #{old}
74
+ EOF
75
+ end
76
+
77
+ exec ["#{ENV["EDITOR"]} #{file}",
78
+ "git commit -aqm '#{message}'",
79
+ "git tag -a -m '#{message}' v#{version}",
80
+ "echo '\n\n\033[32mMarked v#{version} /' `git show-ref -s refs/heads/master` 'for release. Run: rake changeling:push\033[0m\n\n'"].join(' && ')
81
+ end
82
+
83
+ desc "Bump by a minor version (1.2.3 => 1.3.0)"
84
+ task :minor do |t|
85
+ Rake::Task['changeling:bump'].invoke(t.name)
86
+ Rake::Task['changeling:change'].invoke
87
+ end
88
+
89
+ desc "Bump by a patch version, (1.2.3 => 1.2.4)"
90
+ task :patch do |t|
91
+ Rake::Task['changeling:bump'].invoke(t.name)
92
+ Rake::Task['changeling:change'].invoke
93
+ end
94
+
95
+ desc "Push the latest version and tags"
96
+ task :push do |t|
97
+ system("git push origin master")
98
+ system("git push origin $(git tag | tail -1)")
99
+ end
100
+ end
101
+
102
+ begin
103
+ require 'yard'
104
+ YARD::Rake::YardocTask.new do |t|
105
+ t.files = ['lib/**/*.rb', 'TESTING.rdoc']
106
+ end
107
+ rescue LoadError
108
+ end
109
+
110
+ GEM_ROOT = File.dirname(__FILE__).freeze
111
+ VERSION_FILE = File.join(GEM_ROOT, 'lib', 'hoptoad_notifier', 'version')
112
+
113
+ require VERSION_FILE
114
+
115
+ gemspec = Gem::Specification.new do |s|
116
+ s.name = %q{hoptoad_notifier}
117
+ s.version = HoptoadNotifier::VERSION
118
+ s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}
119
+
120
+ s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
121
+ 'test/**/*.rb', 'rails/**/*.rb', 'script/*',
122
+ 'lib/templates/*.erb']
123
+ s.require_path = 'lib'
124
+ s.test_files = Dir[*['test/**/*_test.rb']]
125
+
126
+ s.add_runtime_dependency("builder")
127
+ s.add_runtime_dependency("activesupport")
128
+ s.add_development_dependency("activerecord")
129
+ s.add_development_dependency("actionpack")
130
+ s.add_development_dependency("bourne")
131
+ s.add_development_dependency("nokogiri")
132
+ s.add_development_dependency("shoulda")
133
+
134
+ s.authors = ["thoughtbot, inc"]
135
+ s.email = %q{support@hoptoadapp.com}
136
+ s.homepage = "http://www.hoptoadapp.com"
137
+
138
+ s.platform = Gem::Platform::RUBY
139
+ end
140
+
141
+ Rake::GemPackageTask.new gemspec do |pkg|
142
+ pkg.need_tar = true
143
+ pkg.need_zip = true
144
+ end
145
+
146
+ desc "Clean files generated by rake tasks"
147
+ task :clobber => [:clobber_rdoc, :clobber_package]
148
+
149
+ desc "Generate a gemspec file"
150
+ task :gemspec do
151
+ File.open("#{gemspec.name}.gemspec", 'w') do |f|
152
+ f.write gemspec.to_ruby
153
+ end
154
+ end
155
+
156
+ LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
157
+ RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
158
+ LOCAL_GEMS = [['sham_rack', nil], ['capistrano', nil], ['sqlite3-ruby', nil], ['sinatra', nil]] +
159
+ RAILS_VERSIONS.collect { |version| ['rails', version] }
160
+
161
+ task :vendor_test_gems do
162
+ old_gem_path = ENV['GEM_PATH']
163
+ old_gem_home = ENV['GEM_HOME']
164
+ ENV['GEM_PATH'] = LOCAL_GEM_ROOT
165
+ ENV['GEM_HOME'] = LOCAL_GEM_ROOT
166
+ LOCAL_GEMS.each do |gem_name, version|
167
+ gem_file_pattern = [gem_name, version || '*'].compact.join('-')
168
+ version_option = version ? "-v #{version}" : ''
169
+ pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
170
+ existing = Dir.glob(pattern).first
171
+ unless existing
172
+ command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc --backtrace #{version_option} #{gem_name}"
173
+ puts "Vendoring #{gem_file_pattern}..."
174
+ unless system("#{command} 2>&1")
175
+ puts "Command failed: #{command}"
176
+ exit(1)
177
+ end
178
+ end
179
+ end
180
+ ENV['GEM_PATH'] = old_gem_path
181
+ ENV['GEM_HOME'] = old_gem_home
182
+ end
183
+
184
+ Cucumber::Rake::Task.new(:cucumber) do |t|
185
+ t.fork = true
186
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
187
+ end
188
+
189
+ task :cucumber => [:gemspec, :vendor_test_gems]
190
+
191
+ def run_rails_cucumbr_task(version, additional_cucumber_args)
192
+ puts "Testing Rails #{version}"
193
+ if version.empty?
194
+ raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
195
+ end
196
+ ENV['RAILS_VERSION'] = version
197
+ system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature")
198
+ end
199
+
200
+ def define_rails_cucumber_tasks(additional_cucumber_args = '')
201
+ namespace :rails do
202
+ RAILS_VERSIONS.each do |version|
203
+ desc "Test integration of the gem with Rails #{version}"
204
+ task version => [:gemspec, :vendor_test_gems] do
205
+ exit 1 unless run_rails_cucumbr_task(version, additional_cucumber_args)
206
+ end
207
+ end
208
+
209
+ desc "Test integration of the gem with all Rails versions"
210
+ task :all do
211
+ results = RAILS_VERSIONS.map do |version|
212
+ run_rails_cucumbr_task(version, additional_cucumber_args)
213
+ end
214
+
215
+ exit 1 unless results.all?
216
+ end
217
+ end
218
+ end
219
+
220
+ namespace :cucumber do
221
+ namespace :wip do
222
+ define_rails_cucumber_tasks('--tags @wip')
223
+ end
224
+
225
+ define_rails_cucumber_tasks
226
+ end
227
+
@@ -0,0 +1,10 @@
1
+ 2.3.2
2
+ 2.3.4
3
+ 2.3.5
4
+ 2.3.8
5
+ 2.3.9
6
+ 2.3.10
7
+ 3.0.0
8
+ 3.0.1
9
+ 3.0.2
10
+ 3.0.3
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,88 @@
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
+ opt.on('-h', '--heroku', "Use the Heroku addon to provide your Hoptoad API key") {|v| options[:heroku] = v}
8
+ end
9
+
10
+ def manifest
11
+ if !api_key_configured? && !options[:api_key] && !options[:heroku]
12
+ puts "Must pass --api-key or --heroku or create config/initializers/hoptoad.rb"
13
+ exit
14
+ end
15
+ if plugin_is_present?
16
+ puts "You must first remove the hoptoad_notifier plugin. Please run: script/plugin remove hoptoad_notifier"
17
+ exit
18
+ end
19
+ record do |m|
20
+ m.directory 'lib/tasks'
21
+ m.file 'hoptoad_notifier_tasks.rake', 'lib/tasks/hoptoad_notifier_tasks.rake'
22
+ if ['config/deploy.rb', 'Capfile'].all? { |file| File.exists?(file) }
23
+ m.append_to 'config/deploy.rb', capistrano_hook
24
+ end
25
+ if api_key_expression
26
+ if use_initializer?
27
+ m.template 'initializer.rb', 'config/initializers/hoptoad.rb',
28
+ :assigns => {:api_key => api_key_expression}
29
+ else
30
+ m.template 'initializer.rb', 'config/hoptoad.rb',
31
+ :assigns => {:api_key => api_key_expression}
32
+ m.append_to 'config/environment.rb', "require 'config/hoptoad'"
33
+ end
34
+ end
35
+ determine_api_key if heroku?
36
+ m.rake "hoptoad:test --trace", :generate_only => true
37
+ end
38
+ end
39
+
40
+ def api_key_expression
41
+ s = if options[:api_key]
42
+ "'#{options[:api_key]}'"
43
+ elsif options[:heroku]
44
+ "ENV['HOPTOAD_API_KEY']"
45
+ end
46
+ end
47
+
48
+ def determine_api_key
49
+ puts "Attempting to determine your API Key from Heroku..."
50
+ ENV['HOPTOAD_API_KEY'] = heroku_api_key
51
+ if ENV['HOPTOAD_API_KEY'].blank?
52
+ puts "... Failed."
53
+ puts "WARNING: We were unable to detect the Hoptoad API Key from your Heroku environment."
54
+ puts "Your Heroku application environment may not be configured correctly."
55
+ exit 1
56
+ else
57
+ puts "... Done."
58
+ puts "Heroku's Hoptoad API Key is '#{ENV['HOPTOAD_API_KEY']}'"
59
+ end
60
+ end
61
+
62
+ def heroku_api_key
63
+ `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
64
+ end
65
+
66
+ def heroku?
67
+ options[:heroku] ||
68
+ system("grep HOPTOAD_API_KEY config/initializers/hoptoad.rb") ||
69
+ system("grep HOPTOAD_API_KEY config/environment.rb")
70
+ end
71
+
72
+ def use_initializer?
73
+ Rails::VERSION::MAJOR > 1
74
+ end
75
+
76
+ def api_key_configured?
77
+ File.exists?('config/initializers/hoptoad.rb') ||
78
+ system("grep HoptoadNotifier config/environment.rb")
79
+ end
80
+
81
+ def capistrano_hook
82
+ IO.read(source_path('capistrano_hook.rb'))
83
+ end
84
+
85
+ def plugin_is_present?
86
+ File.exists?('vendor/plugins/hoptoad_notifier')
87
+ end
88
+ 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