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

Lookup Representers Dynamically

Open johnallen3d opened this issue 11 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

That could work, yes.

dblock avatar Aug 26 '13 12:08 dblock

Cool, I was thinking about it a little more over the weekend and it possible you'd want to have pluralized versions of representers as well. I'll work something up and submit a pull request. Thanks.

johnallen3d avatar Aug 26 '13 13:08 johnallen3d

Is there any progress on this?

thisiscab avatar Jul 22 '15 14:07 thisiscab

Sorry, I've not been working roar of late and haven't gotten back to this.

johnallen3d avatar Jul 22 '15 15:07 johnallen3d