Sha256: ecea0b956d158de93db58b4bc7bd8148b0dabbc96b0773ca7a17768411eecef9

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

require 'webmachine'
require 'pact_broker/services'
require 'pact_broker/api/decorators'

module PactBroker

  module Resources

    class ErrorHandler
      def self.handle_exception e, response
        response.body = {:message => e.message, :backtrace => e.backtrace }.to_json
        response.code = 500
      end
    end

    class BaseResource < Webmachine::Resource

      include PactBroker::Services

      def identifier_from_path
        request.path_info.each_with_object({}) do | pair, hash|
          hash[pair.first] = CGI::unescape(pair.last)
        end
      end

      def request_base_url
        request.uri.to_s.gsub(/#{request.uri.path}$/,'')
      end

      def handle_exception e
        PactBroker::Resources::ErrorHandler.handle_exception(e, response)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-0.0.7 lib/pact_broker/resources/base_resource.rb
pact_broker-0.0.6 lib/pact_broker/resources/base_resource.rb