Sha256: 648c73ae2cb1bb39a0ce9fd618315303c4e686babf4dca2ee77e990c8b0830e5

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "standard_exceptions/version"

module StandardExceptions

	module ExceptionInterface
		attr_accessor :status

		attr_writer :inner
		def inner
			@inner || self.cause
		end

		# eg. 'Not Found'
		def self.human_name(e_class=self)
			i = e_class.name.rindex('::')
      base_name = e_class.name[(i+2)..-1]
			base_name.split(/(?=[A-Z])/).join(' ')
		end

		def human_name
			self.class.human_name
		end
	end

	# messages are based on http://httpstatuses.com

	class Exception < ::StandardError
		MESSAGE = 'An error occurred that could not be identified'
		STATUS = 500

		include ExceptionInterface

		def initialize(message=nil,status=nil,inner=nil)
			super(message || self.class::MESSAGE)
			@status = (status || self.class::STATUS)
			@inner = inner
		end
	end
end

require 'standard_exceptions/http'
require 'standard_exceptions/application'
require 'standard_exceptions/http_methods'
require 'standard_exceptions/application_methods'

module StandardExceptions::Methods
	include StandardExceptions::HttpMethods
	include StandardExceptions::ApplicationMethods
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
standard_exceptions-0.1.4 lib/standard_exceptions.rb