-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Labels
Description
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
?