Class: Batbugger::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/batbugger/notice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Notice



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/batbugger/notice.rb', line 55

def initialize(args)
  self.args         = args
  self.exception    = args[:exception]
  self.project_root = args[:project_root]
  self.url          = args[:url] || rack_env(:url)

  self.notifier_name    = args[:notifier_name]
  self.notifier_version = args[:notifier_version]
  self.notifier_url     = args[:notifier_url]

  self.ignore              = args[:ignore]              || []
  self.ignore_by_filters   = args[:ignore_by_filters]   || []
  self.backtrace_filters   = args[:backtrace_filters]   || []
  self.params_filters      = args[:params_filters]      || []
  self.parameters          = args[:parameters] ||
                               action_dispatch_params ||
                               rack_env(:params) ||
                               {}
  self.component           = args[:component] || args[:controller] || parameters['controller']
  self.action              = args[:action] || parameters['action']

  self.environment_name = args[:environment_name]
  self.cgi_data         = args[:cgi_data] || args[:rack_env]
  self.backtrace        = Backtrace.parse(exception_attribute(:backtrace, caller), :filters => self.backtrace_filters)
  self.error_class      = exception_attribute(:error_class) {|exception| exception.class.name }
  self.error_message    = exception_attribute(:error_message, 'Notification') do |exception|
    "#{exception.class.name}: #{exception.message}"
  end

  self.hostname         = local_hostname

  self.source_extract_radius = args[:source_extract_radius] || 2
  self.source_extract        = extract_source_from_backtrace

  self.send_request_session     = args[:send_request_session].nil? ? true : args[:send_request_session]

  also_use_rack_params_filters
  find_session_data
  clean_params
  clean_rack_request_data
  set_context
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



33
34
35
# File 'lib/batbugger/notice.rb', line 33

def action
  @action
end

#backtraceObject

Returns the value of attribute backtrace.



7
8
9
# File 'lib/batbugger/notice.rb', line 7

def backtrace
  @backtrace
end

#backtrace_filtersObject

Returns the value of attribute backtrace_filters.



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

def backtrace_filters
  @backtrace_filters
end

#cgi_dataObject

Returns the value of attribute cgi_data.



17
18
19
# File 'lib/batbugger/notice.rb', line 17

def cgi_data
  @cgi_data
end

#componentObject Also known as: controller

Returns the value of attribute component.



30
31
32
# File 'lib/batbugger/notice.rb', line 30

def component
  @component
end

#contextObject

Returns the value of attribute context.



37
38
39
# File 'lib/batbugger/notice.rb', line 37

def context
  @context
end

#environment_nameObject

Returns the value of attribute environment_name.



15
16
17
# File 'lib/batbugger/notice.rb', line 15

def environment_name
  @environment_name
end

#error_classObject

Returns the value of attribute error_class.



9
10
11
# File 'lib/batbugger/notice.rb', line 9

def error_class
  @error_class
end

#error_messageObject

Returns the value of attribute error_message.



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

def error_message
  @error_message
end

#exceptionObject

Returns the value of attribute exception.



5
6
7
# File 'lib/batbugger/notice.rb', line 5

def exception
  @exception
end

#hostnameObject

Returns the value of attribute hostname.



53
54
55
# File 'lib/batbugger/notice.rb', line 53

def hostname
  @hostname
end

#ignoreObject

Returns the value of attribute ignore.



43
44
45
# File 'lib/batbugger/notice.rb', line 43

def ignore
  @ignore
end

#ignore_by_filtersObject

Returns the value of attribute ignore_by_filters.



45
46
47
# File 'lib/batbugger/notice.rb', line 45

def ignore_by_filters
  @ignore_by_filters
end

#notifier_nameObject

Returns the value of attribute notifier_name.



47
48
49
# File 'lib/batbugger/notice.rb', line 47

def notifier_name
  @notifier_name
end

#notifier_urlObject

Returns the value of attribute notifier_url.



51
52
53
# File 'lib/batbugger/notice.rb', line 51

def notifier_url
  @notifier_url
end

#notifier_versionObject

Returns the value of attribute notifier_version.



49
50
51
# File 'lib/batbugger/notice.rb', line 49

def notifier_version
  @notifier_version
end

#parametersObject Also known as: params

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#params_filtersObject

Returns the value of attribute params_filters.



25
26
27
# File 'lib/batbugger/notice.rb', line 25

def params_filters
  @params_filters
end

#project_rootObject

Returns the value of attribute project_root.



39
40
41
# File 'lib/batbugger/notice.rb', line 39

def project_root
  @project_root
end

#send_request_sessionObject

Returns the value of attribute send_request_session.



21
22
23
# File 'lib/batbugger/notice.rb', line 21

def send_request_session
  @send_request_session
end

#session_dataObject

Returns the value of attribute session_data.



35
36
37
# File 'lib/batbugger/notice.rb', line 35

def session_data
  @session_data
end

#source_extractObject

Returns the value of attribute source_extract.



11
12
13
# File 'lib/batbugger/notice.rb', line 11

def source_extract
  @source_extract
end

#source_extract_radiusObject

Returns the value of attribute source_extract_radius.



13
14
15
# File 'lib/batbugger/notice.rb', line 13

def source_extract_radius
  @source_extract_radius
end

#urlObject

Returns the value of attribute url.



41
42
43
# File 'lib/batbugger/notice.rb', line 41

def url
  @url
end

Instance Method Details

#[](method) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/batbugger/notice.rb', line 155

def [](method)
  case method
  when :request
    self
  else
    send(method)
  end
end

#as_json(options = {}) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/batbugger/notice.rb', line 102

def as_json(options = {})
  {
    :notifier => {
      :name => notifier_name,
      :url => notifier_url,
      :version => notifier_version,
      :language => 'ruby'
    },
    :error => {
      :class => error_class,
      :message => error_message,
      :backtrace => backtrace,
      :source => source_extract
    },
    :request => {
      :url => url,
      :component => component,
      :action => action,
      :params => parameters,
      :session => session_data,
      :cgi_data => cgi_data,
      :context => context
    },
    :server => {
      :project_root => project_root,
      :environment_name => environment_name,
      :hostname => hostname
    }
  }
end

#deliverObject



98
99
100
# File 'lib/batbugger/notice.rb', line 98

def deliver
  Batbugger.sender.send_to_batbugger(self)
end

#ignore?Boolean



150
151
152
153
# File 'lib/batbugger/notice.rb', line 150

def ignore?
  ignore.any?(&ignore_by_class?) ||
    ignore_by_filters.any? {|filter| filter.call(self) }
end

#ignore_by_class?(ignored_class = nil) ⇒ Boolean



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/batbugger/notice.rb', line 137

def ignore_by_class?(ignored_class = nil)
  @ignore_by_class ||= Proc.new do |ignored_class|
    case error_class
    when (ignored_class.respond_to?(:name) ? ignored_class.name : ignored_class)
      true
    else
      exception && ignored_class.is_a?(Class) && exception.class < ignored_class
    end
  end

  ignored_class ? @ignore_by_class.call(ignored_class) : @ignore_by_class
end

#to_json(*a) ⇒ Object



133
134
135
# File 'lib/batbugger/notice.rb', line 133

def to_json(*a)
  as_json.to_json(*a)
end