Class: Goliath::Rack::Formatters::PLIST

Inherits:
Object
  • Object
show all
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

Examples:

use Goliath::Rack::Formatters::PLIST, :convert_unknown_to_string => true

Instance Method Summary collapse

Methods included from AsyncMiddleware

#call, #final_response?, #hook_into_callback_chain

Methods included from Validator

safely, validation_error

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

Returns:

  • (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