Module: Airbrake::CurrentUser
- Defined in:
- lib/airbrake/current_user.rb
Class Method Summary collapse
-
.filtered_attributes(controller) ⇒ Object
Returns filtered attributes for current user.
Class Method Details
.filtered_attributes(controller) ⇒ Object
Returns filtered attributes for current user
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/airbrake/current_user.rb', line 5 def self.filtered_attributes(controller) return {} unless controller.respond_to?(:current_user, true) begin user = controller.send(:current_user) rescue # If something goes wrong (perhaps while running rake airbrake:test), # use the first User. user = User.first end # Return empty hash if there are no users. return {} unless user && user.respond_to?(:attributes) # Removes auth-related fields attributes = user.attributes.reject do |k, v| /password|token|login|sign_in|per_page|_at$/ =~ k end # Try to include a URL for the user, if possible. if url_method = [:user_url, :admin_user_url].detect {|m| controller.respond_to?(m) } attributes[:url] = controller.send(url_method, user) end # Return all keys with non-blank values attributes.select {|k,v| v.present? } end |