Class: Rubyception::Entry
- Inherits:
-
Object
- Object
- Rubyception::Entry
- Defined in:
- app/models/rubyception/entry.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#error ⇒ Object
Returns the value of attribute error.
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#format ⇒ Object
Returns the value of attribute format.
-
#id ⇒ Object
Returns the value of attribute id.
-
#method ⇒ Object
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #<<(event) ⇒ Object
- #error? ⇒ Boolean
- #exception(exception) ⇒ Object
- #finalize(event) ⇒ Object
- #flush! ⇒ Object
- #ignore_event?(event) ⇒ Boolean
-
#initialize(event) ⇒ Entry
constructor
A new instance of Entry.
- #set_values(event) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(event) ⇒ Entry
Returns a new instance of Entry.
16 17 18 19 |
# File 'app/models/rubyception/entry.rb', line 16 def initialize(event) set_values event @lines = [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def action @action end |
#backtrace ⇒ Object
Returns the value of attribute backtrace.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def backtrace @backtrace end |
#controller ⇒ Object
Returns the value of attribute controller.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def controller @controller end |
#duration ⇒ Object
Returns the value of attribute duration.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def duration @duration end |
#end_time ⇒ Object
Returns the value of attribute end_time.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def end_time @end_time end |
#error ⇒ Object
Returns the value of attribute error.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def error @error end |
#finished ⇒ Object
Returns the value of attribute finished.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def finished @finished end |
#format ⇒ Object
Returns the value of attribute format.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def format @format end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def id @id end |
#method ⇒ Object
Returns the value of attribute method.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def path @path end |
#start_time ⇒ Object
Returns the value of attribute start_time.
2 3 4 |
# File 'app/models/rubyception/entry.rb', line 2 def start_time @start_time end |
Instance Method Details
#<<(event) ⇒ Object
41 42 43 |
# File 'app/models/rubyception/entry.rb', line 41 def <<(event) @lines << Rubyception::Line.new(event).attrs unless ignore_event?(event) end |
#error? ⇒ Boolean
39 |
# File 'app/models/rubyception/entry.rb', line 39 def error?; error; end |
#exception(exception) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/rubyception/entry.rb', line 56 def exception(exception) lines = exception.backtrace x = 0 lines = lines.collect do |l| parts = l.match(%r{^(#{Regexp.quote(::Rails.root.to_s)}/)?(.*):(\d+):in `(.*?)'$}) next unless parts x += 1 { num: x, msg: parts[2], app_path: parts[1], line_num: parts[3], in: parts[4], url: CGI.escape("file://#{parts[1]}#{parts[2]}"), rails: !parts[1] } end self.backtrace = { name: exception.class.name, message: exception., lines: lines } flush! end |
#finalize(event) ⇒ Object
81 82 83 84 85 |
# File 'app/models/rubyception/entry.rb', line 81 def finalize(event) set_values(event) self.finished = true flush! unless error? end |
#flush! ⇒ Object
110 111 112 |
# File 'app/models/rubyception/entry.rb', line 110 def flush! Rubyception::WebsocketServer.send_all to_json end |
#ignore_event?(event) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/rubyception/entry.rb', line 45 def ignore_event?(event) payload = event.payload case when event.name == 'sql.active_record' && payload[:name] == 'SCHEMA' # SCHEMA sql are things like SHOW TABLES, DESCRIBE USERS true else false end end |
#set_values(event) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/rubyception/entry.rb', line 21 def set_values event payload = event.payload self.controller = payload[:controller].gsub(/Controller$/,'').downcase.underscore self.action = payload[:action] self.path = payload[:path] self.method = payload[:method] self.format = payload[:format] self.error = payload[:exception].present? self.duration = event.duration.to_f.round(2) self.id = event.transaction_id params = payload[:params] params.delete 'controller' params.delete 'action' self.params = params self.start_time = event.time.to_s :entry self.end_time = event.end.to_s :entry end |
#to_json ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/rubyception/entry.rb', line 87 def to_json methods = %w{controller params action path method format error duration id backtrace finished start_time end_time} result = {} methods.each do |method| method = method.to_sym result[method] = self.send method end result = result.merge lines: @lines result.to_json end |