Code Monkey home page Code Monkey logo

Comments (7)

apotonick avatar apotonick commented on August 27, 2024

Interesting case. An easy place to implement this is in Representable::Binding#extend_for: https://github.com/apotonick/representable/blob/master/lib/representable/binding.rb#L39

It could be overwritten like

def extend_for(object)
  if definition.representer_module.is_a?(PolymorphicExtender)
    object.extend PolymorphicExtender.compute_representer_for(object)
  end
 super

I'm not sure if this should be put into the Roar core, however. What do you think?

from roar.

chrisupb avatar chrisupb commented on August 27, 2024

Hmm I think, according to your blog post, the possibility to create RESTful collection resources with roar died. :(

http://nicksda.apotomo.de/2012/01/ruby-on-rest-3-one-model-multiple-representations/
I wanted to emphasize that the representer doesnโ€™t guess anything from the represented object.[..]. No magic or implicit semantics in Roar. And this is a good thing.

no wait. let me think ^^

from roar.

apotonick avatar apotonick commented on August 27, 2024

Hey, don't cry. We already have collections, however, they assume all items have the same type. There's nothing to say against a polymorphic resolver! What I tried to say in my recent blog post is that we don't fuck around with the represented model per default. Fucking around if the represented model wants that, however, is absolutely ok.

from roar.

chrisupb avatar chrisupb commented on August 27, 2024

Ok I understand. Your blog post is devoted to Steve Klabnik's comment. Hmm he's a REST hardliner...

I tried to hack representable.rb#collection half day... Wrong place =)

So if no :class is given, a PolymorphicExtender will do the work.

But what could be a good convention for naming?
User => UserRepresenter
Users::Profile => Users::ProfileRepresenter

from roar.

chrisupb avatar chrisupb commented on August 27, 2024

If you define no :class or :extend https://github.com/apotonick/representable/blob/master/lib/representable/binding.rb#L39 is never called. Instead standard to_json is called directly.

from roar.

apotonick avatar apotonick commented on August 27, 2024

Yo, here's an example how to implement the PolymorphicExtender, you can simply use :extend and the #extended hook. trailblazer/representable@390335f Works only for rendering, we'd have to provide some type infos for deserialization in the document.

from roar.

apotonick avatar apotonick commented on August 27, 2024

Use representable <= 1.2.9 and do it like this, bro: https://github.com/apotonick/representable/#polymorphic-extend

from roar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.