Class: Exceptional::ControllerExceptionData

Inherits:
ExceptionData show all
Defined in:
lib/exceptional/controller_exception_data.rb

Instance Method Summary collapse

Methods inherited from ExceptionData

#context_stuff, #extract_http_headers, sanitize_hash, sanitize_session, #to_hash, #to_json, #uniqueness_hash

Constructor Details

#initialize(exception, controller = nil, request = nil) ⇒ ControllerExceptionData

Returns a new instance of ControllerExceptionData.



5
6
7
8
9
# File 'lib/exceptional/controller_exception_data.rb', line 5

def initialize(exception, controller=nil, request=nil)
  super(exception)
  @request = request
  @controller = controller
end

Instance Method Details

#extra_stuffObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/exceptional/controller_exception_data.rb', line 15

def extra_stuff                                                                                               
  return {} if @request.nil?
  {
    'request' => {
      'url' => (@request.respond_to?(:url) ? @request.url : "#{@request.protocol}#{@request.host}#{@request.request_uri}"),
      'controller' => @controller.class.to_s,
      'action' => (@request.respond_to?(:parameters) ? @request.parameters['action'] : @request.params['action']),
      'parameters' => filter_parameters(@request.respond_to?(:parameters) ? @request.parameters : @request.params),
      'request_method' => @request.request_method.to_s,
      'remote_ip' => (@request.respond_to?(:remote_ip) ? @request.remote_ip : @request.ip),
      'headers' => extract_http_headers(@request.env),
      'session' => self.class.sanitize_session(@request)
    }
  }
end

#filter_hash(keys_to_filter, hash) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exceptional/controller_exception_data.rb', line 31

def filter_hash(keys_to_filter, hash)
  keys_to_filter.map! {|x| x.to_s}
  if keys_to_filter.is_a?(Array) && !keys_to_filter.empty?
    hash.each do |key, value|
      if key_match?(key, keys_to_filter)
        hash[key] = "[FILTERED]"
      elsif value.respond_to?(:to_hash)
        filter_hash(keys_to_filter, hash[key])
      end
    end
  end
  hash
end

#filter_parameters(hash) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/exceptional/controller_exception_data.rb', line 55

def filter_parameters(hash)
  if @request.respond_to?(:env) && @request.env["action_dispatch.parameter_filter"]
    filter_hash(@request.env["action_dispatch.parameter_filter"], hash)
  elsif @controller.respond_to?(:filter_parameters)
    @controller.send(:filter_parameters, hash)
  else
    hash
  end
end

#frameworkObject



11
12
13
# File 'lib/exceptional/controller_exception_data.rb', line 11

def framework
  "rails"
end

#key_match?(key, keys_to_filter) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/exceptional/controller_exception_data.rb', line 48

def key_match?(key, keys_to_filter)
  keys_to_filter.any? { |k|
    regexp = k.is_a?(Regexp)? k : Regexp.new(k, true)
    key =~ regexp
  }
end