Class: Goliath::Rack::Formatters::PLIST
- Inherits:
-
Object
- Object
- Goliath::Rack::Formatters::PLIST
- Includes:
- AsyncMiddleware
- Defined in:
- lib/goliath/rack/formatters/plist.rb
Overview
A plist formatter. Pass in to_plist options as an option to the middleware
Instance Method Summary collapse
-
#initialize(app, opts = {}) ⇒ PLIST
constructor
A new instance of PLIST.
- #plist_response?(headers) ⇒ Boolean
- #post_process(env, status, headers, body) ⇒ Object
Methods included from AsyncMiddleware
#call, #final_response?, #hook_into_callback_chain
Methods included from Validator
Constructor Details
#initialize(app, opts = {}) ⇒ PLIST
Returns a new instance of PLIST.
11 12 13 14 15 16 17 |
# File 'lib/goliath/rack/formatters/plist.rb', line 11 def initialize(app, opts = {}) unless Hash.new.respond_to? :to_plist fail "Please require a plist library that adds a to_plist method" end @app = app @opts = opts end |
Instance Method Details
#plist_response?(headers) ⇒ Boolean
26 27 28 |
# File 'lib/goliath/rack/formatters/plist.rb', line 26 def plist_response?(headers) headers['Content-Type'] =~ %r{^application/x-plist} end |
#post_process(env, status, headers, body) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/goliath/rack/formatters/plist.rb', line 19 def post_process(env, status, headers, body) if plist_response?(headers) body = [body.to_plist(@opts)] end [status, headers, body] end |