Sha256: 436775a1be2c3eab86650f97b2f2389797b84faf5182eec4dcb11d5ddd69b85b

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

#--
# Copyright (c) 2007 - 2013 Jeremy Hinegardner
# All rights reserved. Licensed under the BSD license. See LICENSE for details
#++

require 'rack'
require 'erb'

module Heel

  class ErrorResponse

    attr_reader :base_uri

    class << self
      def template_file
        @template_file ||= Heel::Configuration.data_path("error.rhtml")
      end

      def template
        @template ||= ::ERB.new(File.read(template_file))
      end

      def homepage
        @homepage ||= Heel::Configuration::HOMEPAGE
      end
    end

    def initialize(base_uri, body, status = 404, header = {})
      header    = header.merge( "Content-Type" => 'text/html' )
      @response = Rack::Response.new('', status, header )
      @base_uri = base_uri
    end

    def finish
      template_vars = TemplateVars.new( :status   => @response.status,
                                        :message  => Rack::Utils::HTTP_STATUS_CODES[@response.status],
                                        :base_uri => base_uri,
                                        :homepage => ErrorResponse.homepage )

      content  = ErrorResponse.template.result( template_vars.binding_for_template )
      @response.write( content )
      return @response.finish
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
heel-4.0.1 lib/heel/error_response.rb
heel-4.0.0 lib/heel/error_response.rb
heel-3.2.1 lib/heel/error_response.rb
heel-3.2.0 lib/heel/error_response.rb
heel-3.1.3 lib/heel/error_response.rb
heel-3.1.2 lib/heel/error_response.rb
heel-3.1.1 lib/heel/error_response.rb
heel-3.1.0 lib/heel/error_response.rb