Sha256: b8a2654899a75ca7d7e35d8a6c0200886285642d67f4daa7f5f911db1f0f7099

Contents?: true

Size: 499 Bytes

Versions: 12

Compression:

Stored size: 499 Bytes

Contents

require 'htmlentities'
#
# We are opening up Exception and adding to_xml and to_json.
#
class Exception

  def exception_type
    self.class.to_s ? self.class.to_s.split("::").last : 'None'
  end

  def to_xml
    "<errors><error>#{HTMLEntities.new.encode(self.message)}</error><type>#{self.exception_type}</type></errors>"
  end

  def to_json
    "{\"error\":#{ActiveSupport::JSON.encode(self.message.gsub(/\r/, ' ').gsub(/\n/, ' ').squeeze(' '))}, \"type\":\"#{self.exception_type}\"}"
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
egregious-0.2.8 lib/egregious/extensions/exception.rb
egregious-0.2.7 lib/egregious/extensions/exception.rb
egregious-0.2.6 lib/egregious/extensions/exception.rb
egregious-0.2.5 lib/egregious/extensions/exception.rb
egregious-0.2.5.pre lib/egregious/extensions/exception.rb
egregious-0.2.4 lib/egregious/extensions/exception.rb
egregious-0.2.3 lib/egregious/extensions/exception.rb
egregious-0.2.2 lib/egregious/extensions/exception.rb
egregious-0.2.1 lib/egregious/extensions/exception.rb
egregious-0.2.0 lib/egregious/extensions/exception.rb
egregious-0.1.7 lib/egregious/extensions/exception.rb
egregious-0.1.6 lib/egregious/extensions/exception.rb