Sha256: fa63185b72700188777026954b777ca80249f4486f83d073c5fbfdab3195530f

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

class RailsExceptionHandler::Storage
  def self.active_record(info)
    ErrorMessage.create(info)
  end

  def self.rails_log(info)
    message = ""
    info.each do |key,val|
      message += "#{key.upcase}: #{val.to_s}\n"
    end
    Rails.logger.fatal(message)
  end

  def self.remote_url(target, info)
    uri = URI.parse(target)
    params = flatten_hash({:error_message => info})
    Net::HTTP::post_form(uri, params)
  end

  private

  # Credit: Hash flattening technique borrowed from Peter Marklund: http://marklunds.com/articles/one/314
  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

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_exception_handler-2.0.0 lib/rails_exception_handler/storage.rb