module Roda::RodaPlugins::JsonParser

def self.configure(app, opts=OPTS)

only wrap values that are not already hashes.
:always will wrap all values, and a value of :unless_hash will
(such as an array) is uploaded in JSON format. A value of
key. Without this, calls to +r.params+ will fail if a non-Hash
:wrap :: Whether to wrap uploaded JSON data in a hash with a "_json"
to respond to +call(str, request)+.
object as the second argument, so the parser needs
:include_request :: If true, the parser will be called with the request
parsed data. The default is to call JSON.parse.
an object that responds to +call(str)+ and returns the
:parser :: The parser to use for parsing incoming json. Should be
halt on the request or raise an exception.
with the request object, and should probably call
parsing a JSON request body. The proc is called
:error_handler :: A proc to call if an exception is raised when
Handle options for the json_parser plugin:
def self.configure(app, opts=OPTS)
  app.opts[:json_parser_error_handler] = opts[:error_handler] || app.opts[:json_parser_error_handler] || DEFAULT_ERROR_HANDLER
  app.opts[:json_parser_parser] = opts[:parser] || app.opts[:json_parser_parser] || app.opts[:json_parser] || JSON.method(:parse)
  app.opts[:json_parser_include_request] = opts[:include_request] if opts.has_key?(:include_request)
  case opts[:wrap]
  when :unless_hash, :always
    app.opts[:json_parser_wrap] = opts[:wrap]
  when nil
    # Nothing
  else
    raise RodaError, "unsupported option value for json_parser plugin :wrap option: #{opts[:wrap].inspect} (should be :unless_hash or :always)"
  end
end