Class: RailsLogParser::Action

Inherits:
Object
  • Object
show all
Extended by:
Enumerize
Defined in:
lib/rails_log_parser/action.rb

Constant Summary collapse

SEVERITIES =
%i[debug info warn error fatal].freeze
KNOWN_EXCEPTIONS =
{
  'ActiveRecord::RecordNotFound' => :fatal,
  'ActionController::RoutingError' => :fatal,
  "Can't verify CSRF token authenticity." => :warn,
  'ActionController::InvalidAuthenticityToken' => :fatal,
  'ActionController::UnfilteredParameters' => :fatal,
}.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, id) ⇒ Action

Returns a new instance of Action.



25
26
27
28
29
30
31
# File 'lib/rails_log_parser/action.rb', line 25

def initialize(type, id)
  self.type = type
  @id = id
  @messages = []
  @stacktrace = []
  self.class.last = self
end

Class Attribute Details

.lastObject

Returns the value of attribute last.



8
9
10
# File 'lib/rails_log_parser/action.rb', line 8

def last
  @last
end

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



23
24
25
# File 'lib/rails_log_parser/action.rb', line 23

def datetime
  @datetime
end

Instance Method Details

#add_message(value) ⇒ Object



59
60
61
62
# File 'lib/rails_log_parser/action.rb', line 59

def add_message(value)
  @messages.push(value)
  @headline = value if @headline.nil?
end

#add_stacktrace(value) ⇒ Object



64
65
66
# File 'lib/rails_log_parser/action.rb', line 64

def add_stacktrace(value)
  @stacktrace.push(value)
end

#after?(datetime) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rails_log_parser/action.rb', line 55

def after?(datetime)
  @datetime > datetime
end

#headlineObject



47
48
49
# File 'lib/rails_log_parser/action.rb', line 47

def headline
  @headline.presence || @messages.first
end

#known_exception?(key = nil) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/rails_log_parser/action.rb', line 41

def known_exception?(key = nil)
  @messages.any? do |message|
    KNOWN_EXCEPTIONS.any? { |e, s| message.include?(e) && severity == s && (key.nil? || key == e) }
  end
end

#severity=(value) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rails_log_parser/action.rb', line 33

def severity=(value)
  value = value.downcase.to_sym
  return unless severity.nil? || SEVERITIES.index(severity.to_sym) < SEVERITIES.index(value)

  super(value)
  @headline = nil
end