airbrake_user_attributes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency("sham_rack", "~> 1.3.0")
23
23
  s.add_development_dependency("shoulda", "~> 2.11.3")
24
24
 
25
- s.add_dependency 'airbrake', '>= 3.0.9'
25
+ s.add_dependency 'airbrake', '3.0.9'
26
26
 
27
27
  end
@@ -0,0 +1,21 @@
1
+ module Airbrake
2
+ module CurrentUser
3
+
4
+ # Returns filtered attributes for current user
5
+ def self.filtered_attributes(controller)
6
+ return {} unless controller.respond_to?(:current_user, true)
7
+ user = controller.send(:current_user)
8
+ # Removes auth-related fields
9
+ attributes = user.attributes.reject do |k, v|
10
+ /password|token|login|sign_in|per_page|_at$/ =~ k
11
+ end
12
+ # Try to include a URL for the user, if possible.
13
+ if url_method = [:user_url, :admin_user_url].detect {|m| controller.respond_to?(m) }
14
+ attributes[:url] = controller.send(url_method, user)
15
+ end
16
+ # Return all keys with non-blank values
17
+ attributes.select {|k,v| v.present? }
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Airbrake
2
+ class << self
3
+ private
4
+
5
+ def build_notice_for_with_current_user(exception, opts = {})
6
+ if opts[:rack_env] && controller = opts[:rack_env]['action_controller.instance']
7
+ opts[:user_attributes] = Airbrake::CurrentUser.filtered_attributes(controller)
8
+ end
9
+ build_notice_for_without_current_user(exception, opts)
10
+ end
11
+ alias_method_chain :build_notice_for, :current_user
12
+
13
+ end
14
+ end
@@ -3,30 +3,15 @@ require 'airbrake/rails/controller_methods'
3
3
  module Airbrake
4
4
  module Rails
5
5
  module ControllerMethods
6
+ private
6
7
 
7
8
  def airbrake_request_data_with_user_attributes
8
- data = airbrake_request_data_without_user_attributes
9
- data[:user_attributes] = current_user_filtered_attributes if respond_to?(:current_user, true)
10
- data
9
+ airbrake_request_data_without_user_attributes.merge(
10
+ :user_attributes => Airbrake::CurrentUser.filtered_attributes(self)
11
+ )
11
12
  end
12
13
  alias_method_chain :airbrake_request_data, :user_attributes
13
14
 
14
- private
15
-
16
- # Returns filtered attributes for current user (removes auth-related fields)
17
- def current_user_filtered_attributes
18
- attributes = current_user.attributes.reject do |k, v|
19
- /password|token|login|sign_in|per_page|_at$/ =~ k
20
- end
21
- # Try to include a URL for the user, if possible.
22
- if url_method = [:user_url, :admin_user_url].detect {|m| respond_to?(m) }
23
- attributes[:url] = send(url_method, current_user)
24
- end
25
- # Return all keys with non-blank values
26
- attributes.select {|k,v| v.present? }
27
- end
28
-
29
15
  end
30
16
  end
31
17
  end
32
-
@@ -1,3 +1,6 @@
1
1
  require 'airbrake'
2
+
3
+ require 'airbrake/current_user'
4
+ require 'airbrake_overrides/airbrake'
2
5
  require 'airbrake_overrides/notice'
3
6
  require 'airbrake_overrides/rails/controller_methods'
@@ -1,3 +1,3 @@
1
1
  module AirbrakeUserAttributes
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake_user_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ dependencies:
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
- - - ! '>='
163
+ - - '='
164
164
  - !ruby/object:Gem::Version
165
165
  version: 3.0.9
166
166
  type: :runtime
@@ -168,7 +168,7 @@ dependencies:
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
171
- - - ! '>='
171
+ - - '='
172
172
  - !ruby/object:Gem::Version
173
173
  version: 3.0.9
174
174
  description: Adds information about the current user to error reports
@@ -182,6 +182,8 @@ files:
182
182
  - README.md
183
183
  - Rakefile
184
184
  - airbrake_user_attributes.gemspec
185
+ - lib/airbrake/current_user.rb
186
+ - lib/airbrake_overrides/airbrake.rb
185
187
  - lib/airbrake_overrides/notice.rb
186
188
  - lib/airbrake_overrides/rails/controller_methods.rb
187
189
  - lib/airbrake_user_attributes.rb
@@ -203,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
205
  version: '0'
204
206
  segments:
205
207
  - 0
206
- hash: 817822340806227861
208
+ hash: 3324931057514553385
207
209
  required_rubygems_version: !ruby/object:Gem::Requirement
208
210
  none: false
209
211
  requirements:
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
214
  version: '0'
213
215
  segments:
214
216
  - 0
215
- hash: 817822340806227861
217
+ hash: 3324931057514553385
216
218
  requirements: []
217
219
  rubyforge_project:
218
220
  rubygems_version: 1.8.24