module IntrospectiveGrape::Formatter::CamelJson
Public Class Methods
call(object, env)
click to toggle source
# File lib/introspective_grape/formatter/camel_json.rb, line 17 def call(object, env) Grape::Formatter::Json.call(transform_to_camel_keys(object), env) end
transform_to_camel_keys(object)
click to toggle source
# File lib/introspective_grape/formatter/camel_json.rb, line 8 def transform_to_camel_keys(object) # We only need to parse(object.to_json) like this if it isn't already # a native hash (or array of them), i.e. we have to parse Grape::Entities # and other formatter facades: has_hash = (object.is_a?(Array) && object.first.is_a?(Hash)) || object.is_a?(Hash) object = JSON.parse(object.to_json) if object.respond_to?(:to_json) && !has_hash CamelSnakeKeys.camel_keys(object) end