fucking_fail 0.0.1

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 (2) hide show
  1. data/lib/fucking_fail.rb +85 -0
  2. metadata +55 -0
@@ -0,0 +1,85 @@
1
+ require 'net/http'
2
+ require 'rack'
3
+
4
+ class FuckingFail
5
+
6
+ DEFAULT_POST_URL = 'http://fuckingfail.com/fails'
7
+ DEFAULT_ON_ERROR = [ 500, {'Content-Type' => 'text/plain'}, [] ]
8
+
9
+ def self.formatted_error error
10
+ error.class.name + ': ' + error.message + "\n" + error.backtrace.join("\n")
11
+ end
12
+
13
+ def self.env_variable
14
+ 'rack.fucking_fail'
15
+ end
16
+
17
+ # The Rack application
18
+ # @return [#call]
19
+ attr_accessor :app
20
+
21
+ # The token for this application as registered on FuckingFail.com
22
+ # @return [String]
23
+ attr_accessor :app_token
24
+
25
+ # The URL that we POST fails to.
26
+ # @return [String] (http://fuckingfail.com/fails)
27
+ attr_accessor :post_url
28
+
29
+ # The Rack response that we return when an unhandled exception is caught
30
+ # @return [Array(Fixnum, Hash, #each)]
31
+ attr_accessor :on_error
32
+
33
+ def on_error #:nodoc:
34
+ @on_error || DEFAULT_ON_ERROR
35
+ end
36
+
37
+ def post_url #:nodoc:
38
+ @post_url || DEFAULT_POST_URL
39
+ end
40
+
41
+ def initialize app, options = nil
42
+ raise ArgumentError, 'You must pass a valid Rack Application' unless app.respond_to?(:call)
43
+
44
+ @app = app
45
+
46
+ options.each {|key, value| send "#{ key }=", value } if options
47
+ end
48
+
49
+ def call env
50
+ env[FuckingFail.env_variable] = self
51
+
52
+ if defined? ActionController::Base
53
+ unless ActionController::Base.instance_methods.include?('rescue_action_with_fucking_fail')
54
+ ActionController::Base.send :include, RailsFail
55
+ end
56
+ end
57
+
58
+ begin
59
+ response = @app.call env
60
+ rescue Exception => ex
61
+ request = Rack::Request.new env
62
+ deliver ex, :params => request.params.inspect, :ip_address => request.ip, :source => request.url
63
+ on_error
64
+ end
65
+ end
66
+
67
+ def deliver exception, additional_data
68
+ uri = URI.parse('http://fuckingfail.com/fails')
69
+ params = additional_data.merge :app_token => app_token, :stacktrace => FuckingFail.formatted_error(exception)
70
+ Net::HTTP.post_form uri, params
71
+ end
72
+
73
+ end
74
+
75
+ module RailsFail
76
+ def self.included base
77
+ base.instance_eval { alias_method_chain :rescue_action, :fucking_fail }
78
+ end
79
+
80
+ def rescue_action_with_fucking_fail exception
81
+ request.env['rack.fucking_fail'].deliver exception, :params => params.inspect, :ip_address => request.ip,
82
+ :source => request.url
83
+ rescue_action_without_fucking_fail exception
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fucking_fail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Track your Fucking FAIL!
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/fucking_fail.rb
26
+ has_rdoc: true
27
+ homepage: http://github.com/devfu/fucking_fail
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Track your Fucking FAIL!
54
+ test_files: []
55
+