Class: Heel::ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/heel/error_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, body, status = 404, header = {}) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.


29
30
31
32
33
# File 'lib/heel/error_response.rb', line 29

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

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri


13
14
15
# File 'lib/heel/error_response.rb', line 13

def base_uri
  @base_uri
end

Class Method Details

.homepageObject


24
25
26
# File 'lib/heel/error_response.rb', line 24

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

.templateObject


20
21
22
# File 'lib/heel/error_response.rb', line 20

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

.template_fileObject


16
17
18
# File 'lib/heel/error_response.rb', line 16

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

Instance Method Details

#finishObject


35
36
37
38
39
40
41
42
43
44
# File 'lib/heel/error_response.rb', line 35

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