grape-roar icon indicating copy to clipboard operation
grape-roar copied to clipboard

Lookup Representers Dynamically

Open johnallen3d opened this issue 10 years ago • 4 comments

Would you consider adding support for automatically extending object with the appropriate representer and releasing this as a gem?

Say something along these lines of:

def call(object, env)
  representer_name = "#{object.class}Representer"

  if Object.const_definied?(representer_name)
    representer_class = Object.const_get()
    object.extend(representer_class)
  end

  Grape::Formatter::Json.call object, env
end

johnallen3d avatar Aug 23 '13 23:08 johnallen3d