class RailsExceptionHandler::Storage
Public Class Methods
Source
# File lib/rails_exception_handler/storage.rb, line 2 def self.active_record(info) if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0 RailsExceptionHandler::ActiveRecord::ErrorMessage.create(info, :without_protection => true) if RailsExceptionHandler::ActiveRecord::ErrorMessage.respond_to?(:create) else RailsExceptionHandler::ActiveRecord::ErrorMessage.create(info) if RailsExceptionHandler::ActiveRecord::ErrorMessage.respond_to?(:create) end end
Source
# File lib/rails_exception_handler/storage.rb, line 33 def self.email(recipients,info) return if recipients.blank? if Rails::VERSION::MAJOR == 3 || (Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR < 2) delivery_method = :deliver else delivery_method = :deliver_now end RailsExceptionHandler::ErrorMailer.send_error_mail_to_admin(info.to_json,recipients).send(delivery_method) end
Notify application admin that an error occured
Source
# File lib/rails_exception_handler/storage.rb, line 62 def self.flat_hash_key(names) names = Array.new(names) name = names.shift.to_s.dup names.each do |n| name << "[#{n}]" end name end
Source
# File lib/rails_exception_handler/storage.rb, line 46 def self.flatten_hash(hash, ancestor_names = []) flat_hash = {} hash.each do |k, v| names = Array.new(ancestor_names) names << k if v.is_a?(Hash) flat_hash.merge!(flatten_hash(v, names)) else key = flat_hash_key(names) key += "[]" if v.is_a?(Array) flat_hash[key] = v end end flat_hash end
Credit: Hash flattening technique borrowed from Peter Marklund: marklunds.com/articles/one/314
Source
# File lib/rails_exception_handler/storage.rb, line 10 def self.mongoid(info) if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0 RailsExceptionHandler::Mongoid::ErrorMessage.create(info, :without_protection => true) if RailsExceptionHandler::Mongoid::ErrorMessage.respond_to?(:create) else RailsExceptionHandler::Mongoid::ErrorMessage.create(info) if RailsExceptionHandler::Mongoid::ErrorMessage.respond_to?(:create) end end
Source
# File lib/rails_exception_handler/storage.rb, line 18 def self.rails_log(info) message = "" info.each do |key,val| message += "#{key.to_s.upcase}: #{val.to_s}\n" end Rails.logger.fatal(message) end
Source
# File lib/rails_exception_handler/storage.rb, line 26 def self.remote_url(target, info) uri = URI.parse(target) params = flatten_hash({:error_message => info}) Net::HTTP::post_form(uri, params) end