Module: Spine::Actions::Responder
- Included in:
- Action
- Defined in:
- lib/spine/actions/responder.rb
Instance Method Summary collapse
- #build_url(url, data) ⇒ Object
- #finish_response ⇒ Object
- #redirect(url, options = {}) ⇒ Object
- #respond(content, options = {}) ⇒ Object
- #responded? ⇒ Boolean
- #send_data(binary, options = {}) ⇒ Object
Instance Method Details
#build_url(url, data) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/spine/actions/responder.rb', line 48 def build_url(url, data) uri = URI(url) query = URI.decode_www_form(uri.query || '') || [] uri.query = URI.encode_www_form(query + data.to_a) uri.to_s end |
#finish_response ⇒ Object
43 44 45 46 |
# File 'lib/spine/actions/responder.rb', line 43 def finish_response @responded = true response end |
#redirect(url, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/spine/actions/responder.rb', line 33 def redirect(url, = {}) response[Rack::CONTENT_TYPE] = 'application/x-www-form-urlencoded' response.redirect( build_url(url, .fetch(:data, {})), .fetch(:status, 302) ) finish_response end |
#respond(content, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/spine/actions/responder.rb', line 11 def respond(content, = {}) response[Rack::CONTENT_TYPE] = .fetch(:content_type) { format.mime_type } response.status = [:status] if [:status] response.write(format.dump(content)) finish_response end |
#responded? ⇒ Boolean
7 8 9 |
# File 'lib/spine/actions/responder.rb', line 7 def responded? @responded end |
#send_data(binary, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spine/actions/responder.rb', line 21 def send_data(binary, = {}) response['Content-Transfer-Encoding'] = 'binary' response[Rack::CONTENT_TYPE] = .fetch(:content_type, 'application/octet-stream') if [:filename] response['Content-Disposition'] = "inline; filename='#{ [:filename] }'" end response.write(binary) finish_response end |