Class: FuckingFail
- Inherits:
-
Object
- Object
- FuckingFail
- Defined in:
- lib/fucking_fail.rb
Constant Summary collapse
- DEFAULT_POST_URL =
'http://fuckingfail.com/fails'
- DEFAULT_ON_ERROR =
[ 500, {'Content-Type' => 'text/plain'}, [] ]
Instance Attribute Summary collapse
-
#app ⇒ #call
The Rack application.
-
#app_token ⇒ String
The token for this application as registered on FuckingFail.com.
-
#on_error ⇒ Object
:nodoc:.
-
#post_url ⇒ Object
:nodoc:.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #deliver(exception, additional_data) ⇒ Object
-
#initialize(app, options = nil) ⇒ FuckingFail
constructor
A new instance of FuckingFail.
Constructor Details
#initialize(app, options = nil) ⇒ FuckingFail
Returns a new instance of FuckingFail.
41 42 43 44 45 46 47 |
# File 'lib/fucking_fail.rb', line 41 def initialize app, = nil raise ArgumentError, 'You must pass a valid Rack Application' unless app.respond_to?(:call) @app = app .each {|key, value| send "#{ key }=", value } if end |
Instance Attribute Details
#app_token ⇒ String
The token for this application as registered on FuckingFail.com
23 24 25 |
# File 'lib/fucking_fail.rb', line 23 def app_token @app_token end |
#on_error ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/fucking_fail.rb', line 31 def on_error @on_error end |
#post_url ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/fucking_fail.rb', line 27 def post_url @post_url end |
Class Method Details
.env_variable ⇒ Object
13 14 15 |
# File 'lib/fucking_fail.rb', line 13 def self.env_variable 'rack.fucking_fail' end |
.formatted_error(error) ⇒ Object
9 10 11 |
# File 'lib/fucking_fail.rb', line 9 def self.formatted_error error error.class.name + ': ' + error. + "\n" + error.backtrace.join("\n") end |
Instance Method Details
#call(env) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fucking_fail.rb', line 49 def call env env[FuckingFail.env_variable] = self if defined? ActionController::Base unless ActionController::Base.instance_methods.include?('rescue_action_with_fucking_fail') ActionController::Base.send :include, RailsFail end end begin response = @app.call env rescue Exception => ex request = Rack::Request.new env deliver ex, :params => request.params.inspect, :ip_address => request.ip, :source => request.url on_error end end |
#deliver(exception, additional_data) ⇒ Object
67 68 69 70 71 |
# File 'lib/fucking_fail.rb', line 67 def deliver exception, additional_data uri = URI.parse('http://fuckingfail.com/fails') params = additional_data.merge :app_token => app_token, :stacktrace => FuckingFail.formatted_error(exception) Net::HTTP.post_form uri, params end |