Sha256: a4a3c9435a5335614bc765ca346191459baf6e4ac164fcfeb6f9954d5a1944a1

Contents?: true

Size: 923 Bytes

Versions: 5

Compression:

Stored size: 923 Bytes

Contents

# coding: UTF-8

module Rescue
  module Controller
    module Dynamic

      def self.included(base)
        base.class_eval do
          define_method Rescue.config.respond_name do |code, exception = nil|
            e = {}
            if e.is_a? Rescue::ApplicationError
              e = { code: e.code, status: e.status, message: e.message }
            else
              e[:code]    = code
              e[:status]  = Rack::Utils::HTTP_STATUS_CODES[code]
              e[:message] = exception.message if exception
            end
  
            respond_to do |format|
              format.html { render status: code, template: "/errors/#{code}" }
              format.json { render status: code, json: { errors: [e] } }
              format.xml  { render status: code, xml:  { errors: [e] } }
            end
          end
        end
        base.extend Rescue::Controller::ClassMethods
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rescue-dog-0.3.2 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.1 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.0 lib/rescue/controllers/dynamic.rb
rescue-dog-0.2.1 lib/rescue/controllers/dynamic.rb
rescue-dog-0.2.0 lib/rescue/controllers/dynamic.rb