If you put present instance, with: Presenter inside a cache block, it cannot be serialized. That is because its implementation looks like this:
def represent(object, options = {})
object.extend self
object
end
The objects gets serialized, but not its class definition with includes the extended methods.
A solution is to roll out a presenter that looks like this:
module Grape
module Roar
module Representer
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def represent(object, options = {})
object.extend self
object.as_json(options) # usually cannot be `to_json` because Grape formatter would re-encode this
end
end
end
end
end
Maybe this should just be a class called Grape::Roar::Representer::JSON?
If you put
present instance, with: Presenterinside a cache block, it cannot be serialized. That is because its implementation looks like this:The objects gets serialized, but not its class definition with includes the extended methods.
A solution is to roll out a presenter that looks like this:
Maybe this should just be a class called
Grape::Roar::Representer::JSON?