Class: Gitlab::Json::GrapeFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/json.rb

Overview

GrapeFormatter is a JSON formatter for the Grape API. This is set in lib/api/api.rb

Class Method Summary collapse

Class Method Details

.call(object, env = nil) ⇒ String

Convert an object to JSON.

The ‘env` param is ignored because it’s not needed in either our formatter or Grape’s, but it is passed through for consistency.

If explicitly supplied with a ‘PrecompiledJson` instance it will skip conversion and return it directly. This is mostly used in caching.

Parameters:

  • object (Object)

Returns:

  • (String)


191
192
193
194
195
# File 'lib/gitlab/json.rb', line 191

def self.call(object, env = nil)
  return object.to_s if object.is_a?(PrecompiledJson)

  Gitlab::Json.dump(object)
end