Class: Rubyception::Entry

Inherits:
Object
  • Object
show all
Defined in:
app/models/rubyception/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject

Returns the value of attribute action.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def action
  @action
end

#backtraceObject

Returns the value of attribute backtrace.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def backtrace
  @backtrace
end

#controllerObject

Returns the value of attribute controller.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def controller
  @controller
end

#durationObject

Returns the value of attribute duration.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def duration
  @duration
end

#end_timeObject

Returns the value of attribute end_time.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def end_time
  @end_time
end

#errorObject

Returns the value of attribute error.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def error
  @error
end

#finishedObject

Returns the value of attribute finished.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def finished
  @finished
end

#formatObject

Returns the value of attribute format.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def format
  @format
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def id
  @id
end

#methodObject

Returns the value of attribute method.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def method
  @method
end

#paramsObject

Returns the value of attribute params.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def params
  @params
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'app/models/rubyception/entry.rb', line 2

def path
  @path
end

#start_timeObject

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

Returns:

  • (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.message,
    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

Returns:

  • (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_jsonObject



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