Class: Gitlab::Json::PrecompiledJson
- Inherits:
-
Object
- Object
- Gitlab::Json::PrecompiledJson
- 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
- #format ⇒ Object
-
#initialize(value) ⇒ PrecompiledJson
constructor
A new instance of PrecompiledJson.
- #render_in(_view_context) ⇒ Object
-
#to_s ⇒ String
Convert the value to a String.
Constructor Details
#PrecompiledJson.new("foo") ⇒ PrecompiledJson #PrecompiledJson.new(["foo", "bar"]) ⇒ PrecompiledJson
Returns a new instance of PrecompiledJson.
208 209 210 |
# File 'lib/gitlab/json.rb', line 208 def initialize(value) @value = value end |
Instance Method Details
#format ⇒ Object
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_s ⇒ String
Convert the value to a String. This will invoke ‘#to_s` on the members of the value if it’s an array.
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 |