Comments (7)
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.
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.
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.
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.
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.
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.
Use representable <= 1.2.9 and do it like this, bro: https://github.com/apotonick/representable/#polymorphic-extend
from roar.
Related Issues (20)
- Cache the response HOT 3
- [JSON-API] Recursive has_many :children (include tree) HOT 2
- Including Roar::XML modifies the output of Roar::JSON HOT 5
- Allow dynamic link names.
- [JSON-API] Nested relationships don't get built HOT 2
- [JSON-API] Rendering an empty relationship HOT 1
- Using JSONAPI HOT 4
- JSONAPI: Relationship IDs ignore as: :id option HOT 2
- 'links' in 'relationships' only printing last item in collection HOT 1
- Remove test/lib/runner.rb once sinatra-contrib is updated
- passing meta option does not work for JSONAPI HOT 2
- How to conditionally include representer HOT 3
- Exclude/Include of relationships HOT 1
- JSON API Serialize deep relationships HOT 1
- Release 1.1.0 HOT 11
- Option 'embedded' doesn't work in some cases HOT 3
- Deprecate support for module Representers HOT 1
- Custom Formats for DateTime support HOT 9
- Control which properties get shown by options
- roar-rails abandoned HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roar.