Class: Editserver::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/editserver/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(editor, request) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
# File 'lib/editserver/response.rb', line 8

def initialize editor, request
  @editor   = editor
  @request  = request
  @response = Rack::Response.new
end

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



6
7
8
# File 'lib/editserver/response.rb', line 6

def editor
  @editor
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/editserver/response.rb', line 6

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/editserver/response.rb', line 6

def response
  @response
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/editserver/response.rb', line 14

def call
  tempfile = mktemp
  editor.edit tempfile.path
  response.write File.read(tempfile.path)
  response.finish
rescue EditError => e
  response.write e.to_s
  response.status = 500 # server error
  response.finish
ensure
  if tempfile
    tempfile.close
    tempfile.unlink
  end
end