UtopiaSourceUtopiaControllerHandlersJSON

module JSON

Serializes controller values as JSON responses.

Definitions

def self.split(*arguments)

Delegate content-type splitting to the JSON media type.

Signature

parameter arguments Array

The arguments.

returns Array

The resulting values.

Implementation

def self.split(*arguments)
	APPLICATION_JSON.split(*arguments)
end

def self.call(context, request, media_range, object, **options)

Serialize an object as a successful JSON response.

Signature

parameter context Object

The context.

parameter request Rack::Request

The request.

parameter media_range HTTP::Accept::MediaTypes::MediaRange

The negotiated media range.

parameter object Object

The object.

parameter options Hash

The options.

returns Object

The result of Utopia::Controller::Base#succeed!.

Implementation

def self.call(context, request, media_range, object, **options)
	if version = media_range.parameters["version"]
		options[:version] = version.to_s
	end
	
	context.succeed! content: object.to_json(options), type: APPLICATION_JSON
end