Class: Gitlab::Json::PrecompiledJson

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

Overview

Wrapper class used to skip JSON dumping on Grape endpoints.

Constant Summary collapse

UnsupportedFormatError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#PrecompiledJson.new("foo") ⇒ PrecompiledJson #PrecompiledJson.new(["foo", "bar"]) ⇒ PrecompiledJson

Returns a new instance of PrecompiledJson.

Overloads:

  • #PrecompiledJson.new("foo") ⇒ PrecompiledJson

    Parameters:

    • value (String)
  • #PrecompiledJson.new(["foo", "bar"]) ⇒ PrecompiledJson

    Parameters:

    • value (Array<String>)


208
209
210
# File 'lib/gitlab/json.rb', line 208

def initialize(value)
  @value = value
end

Instance Method Details

#formatObject



229
230
231
# File 'lib/gitlab/json.rb', line 229

def format
  :json
end

#render_in(_view_context) ⇒ Object



225
226
227
# File 'lib/gitlab/json.rb', line 225

def render_in(_view_context)
  to_s
end

#to_sString

Convert the value to a String. This will invoke ‘#to_s` on the members of the value if it’s an array.

Returns:

  • (String)

Raises:



218
219
220
221
222
223
# File 'lib/gitlab/json.rb', line 218

def to_s
  return @value if @value.is_a?(String)
  return "[#{@value.join(',')}]" if @value.is_a?(Array)

  raise UnsupportedFormatError
end