Class: FuckingFail

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = nil) ⇒ FuckingFail

Returns a new instance of FuckingFail.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/fucking_fail.rb', line 41

def initialize app, options = nil
  raise ArgumentError, 'You must pass a valid Rack Application' unless app.respond_to?(:call)

  @app = app

  options.each {|key, value| send "#{ key }=", value } if options
end

Instance Attribute Details

#app#call

The Rack application

Returns:



19
20
21
# File 'lib/fucking_fail.rb', line 19

def app
  @app
end

#app_tokenString

The token for this application as registered on FuckingFail.com

Returns:

  • (String)


23
24
25
# File 'lib/fucking_fail.rb', line 23

def app_token
  @app_token
end

#on_errorObject

:nodoc:



31
32
33
# File 'lib/fucking_fail.rb', line 31

def on_error
  @on_error
end

#post_urlObject

:nodoc:



27
28
29
# File 'lib/fucking_fail.rb', line 27

def post_url
  @post_url
end

Class Method Details

.env_variableObject



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.message + "\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