Class: Rscratch::Exception

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rscratch/exception.rb

Constant Summary collapse

STATUS =
%w(new under_development resolved)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create(exc, _controller, _action, _env) ⇒ Object

Log unique exceptions


52
53
54
55
56
57
58
59
60
# File 'app/models/rscratch/exception.rb', line 52

def self.find_or_create exc,_controller,_action,_env              
  _excp = Exception.by_exception(exc.class).by_message(exc.message).by_controller(_controller).by_action(_action).by_environment(_env).first
  unless _excp.present?
    _excp = Exception.new
    _excp.set_attributes_for exc, _controller, _action, _env
    _excp.save!        
  end
  _excp
end

.log(_exception, _request) ⇒ Object

Log an exception


40
41
42
43
44
45
46
47
48
49
# File 'app/models/rscratch/exception.rb', line 40

def self.log(_exception,_request) 
  _exc = self.find_or_create(_exception,_request.filtered_parameters["controller"].camelize,_request.filtered_parameters["action"],Rails.env.camelize)
  unless _exc.ignored?
    _log = ExceptionLog.new
    _log.set_attributes_for _exception,_request
    _exc.exception_logs << _log 
  end
  _exc_log = _exc.exception_logs.last
  return { :exception_id => _exc.id, :log_serial => _exc_log.id, :log_url => "#{_request.base_url}#{Rscratch::Engine.routes.url_helpers.log_exceptions_path(_exc_log)}" }
end

Instance Method Details

#dont_ignore!Object


90
91
92
# File 'app/models/rscratch/exception.rb', line 90

def dont_ignore!
  update_attribute(:is_ignored, false)
end

#ignore!Object


94
95
96
# File 'app/models/rscratch/exception.rb', line 94

def ignore!
  update_attribute(:is_ignored, true)
end

#ignored?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'app/models/rscratch/exception.rb', line 82

def ignored?
  self.is_ignored == true
end

#not_ignored?Boolean

Returns:

  • (Boolean)

86
87
88
# File 'app/models/rscratch/exception.rb', line 86

def not_ignored?
  !ignored?
end

#reset_counter!Object


102
103
104
# File 'app/models/rscratch/exception.rb', line 102

def reset_counter!
  update_attribute(:new_occurance_count, 0)
end

#resolve!Object


76
77
78
79
80
# File 'app/models/rscratch/exception.rb', line 76

def resolve!
  update_attribute(:status, 'resolved')
  self.exception_logs.last.resolve!
  reset_counter!
end

#set_attributes_for(_exception, _controller, _action, _env) ⇒ Object

Sets Exception instance attributes.


63
64
65
66
67
68
69
# File 'app/models/rscratch/exception.rb', line 63

def set_attributes_for _exception, _controller, _action, _env
  self.exception = _exception.class
  self.message = _exception.message
  self.controller = _controller
  self.action = _action
  self.app_environment = _env
end

#set_default_attributesObject

Setting new default attributes


72
73
74
# File 'app/models/rscratch/exception.rb', line 72

def set_default_attributes
  self.status = "new"
end

#toggle_ignore!Object


98
99
100
# File 'app/models/rscratch/exception.rb', line 98

def toggle_ignore!
  ignored? ? dont_ignore! : ignore!
end