lib/egregious.rb in egregious-0.1.7 vs lib/egregious.rb in egregious-0.2.0
- old
+ new
@@ -6,16 +6,17 @@
module Egregious
# use these exception to control the code you are throwing from you code
# all http statuses have an exception defined for them
Rack::Utils::HTTP_STATUS_CODES.each do |key, value|
- class_eval "class #{value.gsub(/\s|-/,'')} < StandardError; end"
+ class_eval "class #{value.gsub(/\s|-|'/,'')} < StandardError; end"
end
def self.status_code(status)
if status.is_a?(Symbol)
- Rack::Utils::HTTP_STATUS_CODES[status] || 500
+ key = status.to_s.split("_").map {|e| e.capitalize}.join(" ")
+ Rack::Utils::HTTP_STATUS_CODES.invert[key] || 500
else
status.to_i
end
end
@@ -31,10 +32,10 @@
exception_codes = {
SecurityError=>status_code(:forbidden)
}
# all status codes have a exception class defined
Rack::Utils::HTTP_STATUS_CODES.each do |key, value|
- exception_codes.merge!(eval("Egregious::#{value.gsub(/\s|-/,'')}")=>value.downcase.gsub(/\s|-/, '_').to_sym)
+ exception_codes.merge!(eval("Egregious::#{value.gsub(/\s|-|'/,'')}")=>value.downcase.gsub(/\s|-/, '_').to_sym)
end
if defined?(ActionController)
exception_codes.merge!({
AbstractController::ActionNotFound=>status_code(:bad_request),