flail 0.0.3 → 0.0.4
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.
- data/.rvmrc +1 -0
- data/Gemfile.lock +43 -0
- data/flail.gemspec +5 -0
- data/lib/flail/exception.rb +22 -22
- data/lib/flail/rails.rb +1 -0
- data/lib/flail/rails/controller_methods.rb +34 -0
- data/lib/flail/rails/rescue_action.rb +2 -1
- data/lib/flail/railtie.rb +5 -0
- data/lib/flail/version.rb +1 -1
- data/spec/rescue_action_spec.rb +45 -0
- data/spec/spec_helper.rb +102 -1
- metadata +87 -2
data/.rvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rvm use 1.9.3@flail
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
flail (0.0.3)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: http://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (2.3.14)
|
|
10
|
+
activesupport (= 2.3.14)
|
|
11
|
+
rack (~> 1.1.0)
|
|
12
|
+
activerecord (2.3.14)
|
|
13
|
+
activesupport (= 2.3.14)
|
|
14
|
+
activesupport (2.3.14)
|
|
15
|
+
diff-lcs (1.1.3)
|
|
16
|
+
fakeweb (1.3.0)
|
|
17
|
+
rack (1.1.3)
|
|
18
|
+
rake (0.9.2.2)
|
|
19
|
+
rr (1.0.4)
|
|
20
|
+
rspec (2.11.0)
|
|
21
|
+
rspec-core (~> 2.11.0)
|
|
22
|
+
rspec-expectations (~> 2.11.0)
|
|
23
|
+
rspec-mocks (~> 2.11.0)
|
|
24
|
+
rspec-core (2.11.1)
|
|
25
|
+
rspec-expectations (2.11.2)
|
|
26
|
+
diff-lcs (~> 1.1.3)
|
|
27
|
+
rspec-mocks (2.11.1)
|
|
28
|
+
sham_rack (1.3.4)
|
|
29
|
+
rack
|
|
30
|
+
|
|
31
|
+
PLATFORMS
|
|
32
|
+
ruby
|
|
33
|
+
|
|
34
|
+
DEPENDENCIES
|
|
35
|
+
actionpack (~> 2.3.8)
|
|
36
|
+
activerecord (~> 2.3.8)
|
|
37
|
+
activesupport (~> 2.3.8)
|
|
38
|
+
fakeweb (~> 1.3.0)
|
|
39
|
+
flail!
|
|
40
|
+
rake
|
|
41
|
+
rr
|
|
42
|
+
rspec
|
|
43
|
+
sham_rack (~> 1.3.0)
|
data/flail.gemspec
CHANGED
|
@@ -18,7 +18,12 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
19
|
s.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
+
s.add_development_dependency 'actionpack', '~> 2.3.8'
|
|
22
|
+
s.add_development_dependency 'activerecord', '~> 2.3.8'
|
|
23
|
+
s.add_development_dependency 'activesupport', '~> 2.3.8'
|
|
24
|
+
s.add_development_dependency 'fakeweb', '~> 1.3.0'
|
|
21
25
|
s.add_development_dependency 'rake'
|
|
22
26
|
s.add_development_dependency 'rspec'
|
|
23
27
|
s.add_development_dependency 'rr'
|
|
28
|
+
s.add_development_dependency 'sham_rack', '~> 1.3.0'
|
|
24
29
|
end
|
data/lib/flail/exception.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
require 'socket'
|
|
2
|
+
require 'json'
|
|
2
3
|
|
|
3
4
|
class Flail
|
|
4
5
|
class Exception
|
|
5
|
-
def initialize(env, exception)
|
|
6
|
+
def initialize(env, exception, local = false)
|
|
6
7
|
@exception = exception
|
|
7
8
|
@env = env
|
|
8
9
|
end
|
|
@@ -18,19 +19,15 @@ class Flail
|
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
def
|
|
22
|
-
@
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{:id => current_user.id, :name => current_user.to_s}
|
|
31
|
-
else
|
|
32
|
-
{}
|
|
33
|
-
end
|
|
22
|
+
def request_data
|
|
23
|
+
@request_data ||= if @env['flail.request.data']
|
|
24
|
+
@env['flail.request.data']
|
|
25
|
+
else
|
|
26
|
+
{
|
|
27
|
+
:parameters => {},
|
|
28
|
+
:user => {},
|
|
29
|
+
}
|
|
30
|
+
end
|
|
34
31
|
end
|
|
35
32
|
|
|
36
33
|
|
|
@@ -45,14 +42,17 @@ class Flail
|
|
|
45
42
|
@extract ||= begin
|
|
46
43
|
info = {}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
info[:
|
|
50
|
-
info[:
|
|
51
|
-
info[:
|
|
52
|
-
info[:
|
|
53
|
-
info[:
|
|
54
|
-
info[:
|
|
55
|
-
info[:
|
|
45
|
+
# rack env
|
|
46
|
+
info[:rack] = @env.to_json(:except => ['flail.request', 'flail.request.data'])
|
|
47
|
+
info[:class_name] = @exception.class.to_s # @exception class
|
|
48
|
+
info[:message] = @exception.to_s # error message
|
|
49
|
+
info[:trace] = @exception.backtrace # backtrace of error
|
|
50
|
+
info[:target_url] = request_data[:target_url] # url of request
|
|
51
|
+
info[:referer_url] = request_data[:referer_url] # referer
|
|
52
|
+
info[:parameters] = request_data[:parameters] # request parameters
|
|
53
|
+
info[:user_agent] = request_data[:user_agent] # user agent
|
|
54
|
+
info[:user] = request_data[:user] # current user
|
|
55
|
+
info[:session_data]= request_data[:session_data] # session
|
|
56
56
|
|
|
57
57
|
# special variables
|
|
58
58
|
info[:environment] = Flail.configuration.env
|
data/lib/flail/rails.rb
CHANGED
|
@@ -3,6 +3,7 @@ require 'flail/rails/rescue_action'
|
|
|
3
3
|
|
|
4
4
|
if defined?(::ActionController::Base)
|
|
5
5
|
::ActionController::Base.send(:include, Flail::Rails::RescueAction)
|
|
6
|
+
::ActionController::Base.send(:include, Flail::Rails::ControllerMethods)
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Flail
|
|
2
|
+
module Rails
|
|
3
|
+
module ControllerMethods
|
|
4
|
+
def flail_request_data
|
|
5
|
+
{
|
|
6
|
+
:parameters => params.to_hash,
|
|
7
|
+
:session_data => flail_session_data,
|
|
8
|
+
:target_url => request.url,
|
|
9
|
+
:referer_url => request.referer,
|
|
10
|
+
:user_agent => request.user_agent,
|
|
11
|
+
:user => flail_user_data
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def flail_session_data
|
|
16
|
+
if session.respond_to?(:to_hash)
|
|
17
|
+
session.to_hash
|
|
18
|
+
else
|
|
19
|
+
session.data
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def flail_user_data
|
|
24
|
+
user = current_user
|
|
25
|
+
|
|
26
|
+
user.attributes.select do |k, v|
|
|
27
|
+
/^(id|name|username|email|login)$/ === k unless v.blank?
|
|
28
|
+
end
|
|
29
|
+
rescue NoMethodError, NameError
|
|
30
|
+
{}
|
|
31
|
+
end
|
|
32
|
+
end # ControllerMethods
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -14,7 +14,8 @@ class Flail
|
|
|
14
14
|
# Rails 2's exception helpers.
|
|
15
15
|
def rescue_action_in_public_with_flail(exception)
|
|
16
16
|
request.env['flail.request'] = request
|
|
17
|
-
request.env['
|
|
17
|
+
request.env['flail.request.data'] = flail_request_data
|
|
18
|
+
|
|
18
19
|
Flail::Exception.new(request.env, exception).handle!
|
|
19
20
|
rescue_action_in_public_without_flail(exception)
|
|
20
21
|
end
|
data/lib/flail/railtie.rb
CHANGED
|
@@ -10,6 +10,11 @@ class Flail
|
|
|
10
10
|
host Socket.gethostname
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
|
14
|
+
require 'flail/rails/controller_methods'
|
|
15
|
+
include Flail::Rails::ControllerMethods
|
|
16
|
+
end
|
|
17
|
+
|
|
13
18
|
if defined?(::ActionDispatch::DebugExceptions)
|
|
14
19
|
# Rails 3.2.x
|
|
15
20
|
require 'flail/rails/action_dispatch'
|
data/lib/flail/version.rb
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'flail/rails/rescue_action'
|
|
4
|
+
|
|
5
|
+
describe Flail::Rails::RescueAction do
|
|
6
|
+
|
|
7
|
+
context "catching requests" do
|
|
8
|
+
before do
|
|
9
|
+
FlailArmory.setup
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before(:each) do
|
|
13
|
+
FlailArmory.raid
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should deliver an exception raised in public requests" do
|
|
17
|
+
FlailArmory.process_action_with_error
|
|
18
|
+
FlailArmory.payload.should_not be_nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should not deliver exceptions in local requests" do
|
|
22
|
+
FlailArmory.process_action_with_error(:local => true)
|
|
23
|
+
FlailArmory.payload.should be_nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should not deliver exceptions when all requests are local" do
|
|
27
|
+
FlailArmory.process_action_with_error(:all_local => true)
|
|
28
|
+
FlailArmory.payload.should be_nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should not deliver exceptions from actions that don't raise" do
|
|
32
|
+
controller = FlailArmory.process_action { render :text => 'Hello' }
|
|
33
|
+
|
|
34
|
+
FlailArmory.payload.should be_nil
|
|
35
|
+
controller.response.body.should == 'Hello'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should send session data" do
|
|
39
|
+
data = {'one' => 'two'}
|
|
40
|
+
FlailArmory.process_action_with_error(:session => data)
|
|
41
|
+
|
|
42
|
+
FlailArmory.payload['session_data'].should == data
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,9 +3,110 @@ require 'bundler'
|
|
|
3
3
|
Bundler.setup
|
|
4
4
|
|
|
5
5
|
require 'rspec'
|
|
6
|
-
require '
|
|
6
|
+
require 'rr'
|
|
7
7
|
|
|
8
8
|
RSpec.configure do |config|
|
|
9
9
|
config.mock_with :rr
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
require 'action_controller'
|
|
13
|
+
require 'action_controller/test_process'
|
|
14
|
+
require 'active_record'
|
|
15
|
+
require 'active_support'
|
|
16
|
+
require 'rack'
|
|
17
|
+
require 'sham_rack'
|
|
18
|
+
|
|
19
|
+
require 'flail'
|
|
20
|
+
require 'flail/rails/controller_methods'
|
|
21
|
+
require 'flail/rails/rescue_action'
|
|
22
|
+
|
|
23
|
+
class FlailArmory
|
|
24
|
+
|
|
25
|
+
module ClassMethods
|
|
26
|
+
def define_constant(name, value)
|
|
27
|
+
@defined_constants ||= []
|
|
28
|
+
Object.const_set(name, value)
|
|
29
|
+
@defined_constants << name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def build_controller_class(&definition)
|
|
33
|
+
Class.new(ActionController::Base).tap do |klass|
|
|
34
|
+
klass.__send__(:include, Flail::Rails::ControllerMethods)
|
|
35
|
+
klass.__send__(:include, Flail::Rails::RescueAction)
|
|
36
|
+
klass.class_eval(&definition) if definition
|
|
37
|
+
|
|
38
|
+
klass.class_eval do
|
|
39
|
+
def rescue_action_in_public_without_flail(*args)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
define_constant('FlailTestController', klass)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def process_action(options = {}, &action)
|
|
47
|
+
options[:request] ||= ActionController::TestRequest.new
|
|
48
|
+
options[:response] ||= ActionController::TestResponse.new
|
|
49
|
+
|
|
50
|
+
klass = build_controller_class do
|
|
51
|
+
cattr_accessor :local
|
|
52
|
+
define_method(:index, &action)
|
|
53
|
+
|
|
54
|
+
def local_request?
|
|
55
|
+
local
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if options[:user_agent]
|
|
60
|
+
if options[:request].respond_to?(:user_agent=)
|
|
61
|
+
options[:request].user_agent = options[:user_agent]
|
|
62
|
+
else
|
|
63
|
+
options[:request].env["HTTP_USER_AGENT"] = options[:user_agent]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
klass.consider_all_requests_local = options[:all_local]
|
|
68
|
+
klass.local = options[:local]
|
|
69
|
+
|
|
70
|
+
controller = klass.new
|
|
71
|
+
options[:request].query_parameters = options[:request].query_parameters.merge(options[:params] || {})
|
|
72
|
+
options[:request].session = ActionController::TestSession.new(options[:session] || {})
|
|
73
|
+
|
|
74
|
+
options[:request].env['REQUEST_URI'] = options[:request].request_uri
|
|
75
|
+
controller.process(options[:request], options[:response])
|
|
76
|
+
controller
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def process_action_with_error(options = {})
|
|
80
|
+
process_action(options) do
|
|
81
|
+
raise "Hello"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def setup
|
|
86
|
+
Flail.configure do
|
|
87
|
+
handle do |payload|
|
|
88
|
+
FlailArmory.payload = ActiveSupport::JSON.decode(payload)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
define_constant('RAILS_ROOT', '/path/to/rails/root')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def payload=(value)
|
|
95
|
+
@payload = value
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def payload
|
|
99
|
+
@payload
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def raid
|
|
103
|
+
@defined_constants.each do |constant|
|
|
104
|
+
Object.__send__(:remove_const, constant)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
@payload = nil
|
|
108
|
+
@defined_constants = []
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
extend ClassMethods
|
|
112
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flail
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,8 +9,72 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-08-
|
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: actionpack
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 2.3.8
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 2.3.8
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: activerecord
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 2.3.8
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 2.3.8
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: activesupport
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ~>
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 2.3.8
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.3.8
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: fakeweb
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ~>
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 1.3.0
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ~>
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: 1.3.0
|
|
14
78
|
- !ruby/object:Gem::Dependency
|
|
15
79
|
name: rake
|
|
16
80
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -59,6 +123,22 @@ dependencies:
|
|
|
59
123
|
- - ! '>='
|
|
60
124
|
- !ruby/object:Gem::Version
|
|
61
125
|
version: '0'
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: sham_rack
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
129
|
+
none: false
|
|
130
|
+
requirements:
|
|
131
|
+
- - ~>
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: 1.3.0
|
|
134
|
+
type: :development
|
|
135
|
+
prerelease: false
|
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
137
|
+
none: false
|
|
138
|
+
requirements:
|
|
139
|
+
- - ~>
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: 1.3.0
|
|
62
142
|
description: Handle Rails exceptions with the fail flail.
|
|
63
143
|
email:
|
|
64
144
|
- machinist@asceth.com
|
|
@@ -69,7 +149,9 @@ files:
|
|
|
69
149
|
- .gemtest
|
|
70
150
|
- .gitignore
|
|
71
151
|
- .rspec
|
|
152
|
+
- .rvmrc
|
|
72
153
|
- Gemfile
|
|
154
|
+
- Gemfile.lock
|
|
73
155
|
- LICENSE
|
|
74
156
|
- README.md
|
|
75
157
|
- Rakefile
|
|
@@ -81,11 +163,13 @@ files:
|
|
|
81
163
|
- lib/flail/rack.rb
|
|
82
164
|
- lib/flail/rails.rb
|
|
83
165
|
- lib/flail/rails/action_dispatch.rb
|
|
166
|
+
- lib/flail/rails/controller_methods.rb
|
|
84
167
|
- lib/flail/rails/rescue_action.rb
|
|
85
168
|
- lib/flail/railtie.rb
|
|
86
169
|
- lib/flail/version.rb
|
|
87
170
|
- rails/init.rb
|
|
88
171
|
- spec/base_spec.rb
|
|
172
|
+
- spec/rescue_action_spec.rb
|
|
89
173
|
- spec/spec_helper.rb
|
|
90
174
|
homepage: https://github.com/asceth/flail
|
|
91
175
|
licenses: []
|
|
@@ -113,4 +197,5 @@ specification_version: 3
|
|
|
113
197
|
summary: Rails exception handler
|
|
114
198
|
test_files:
|
|
115
199
|
- spec/base_spec.rb
|
|
200
|
+
- spec/rescue_action_spec.rb
|
|
116
201
|
- spec/spec_helper.rb
|