Module: TxghServer::RespondWith

Defined in:
lib/txgh-server/application.rb

Instance Method Summary collapse

Instance Method Details

#respond_with(resp) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/txgh-server/application.rb', line 7

def respond_with(resp)
  env['txgh.response'] = resp

  if resp.streaming?
    response.headers.merge!(resp.headers)

    stream do |out|
      begin
        resp.write_to(out)
      rescue => e
        Txgh.events.publish_error!(e)
      end
    end
  else
    status resp.status
    json resp.body
  end
end