Comments (3)
Matt- the :include
and :exclude
options are filtered out on the first level per design. They should be used very moderately since we don't wanna end up with the same problems (aka shit) :as_json
's hash madness had. However, if there's a bunch of people requiring this we could discuss it.
from representable.
Perhaps a way to specify them on the property would be an effective way of doing it. In Roar you can use :embedded => true
to put the property in _embedded
, perhaps allowing :include
, :exclude
or a way to pass an options hash for serialize/deserialize in a similar fashion.
As a simplified use case, consider the above example and adding a property on AlbumRepresenter
for an Artist
which is extended by ArtistRepresenter
and two different UIs that might consume the data, cover-flow and detailed list. Cover-flow may want an Artist
and their Albums
but only album artwork and title.
module ArtistRepresenter
collection :albums, :extend => AlbumRepresenter, :serialize_options => lambda {|opts| opts.delete(:albums)}
end
:serialize_options
takes a NilClass
, Hash
or Proc
and is ignored if nil or absent. This would allow a client to consume the data it wants for its needs while allowing the developer to maintain a single representer. It does not duplicate the same crap as :as_json
with :include
and :except
hash madness, but allows the developer the ability to specify serialization options in the code explicitly or as generated by their own means via options passed to to_hash
or to_json
# For cover-flow where songs are not needed
artist.to_hash(:albums => {:include => [:title, :album_artwork]})
# For detailed list where album artwork is not needed
artist.to_hash(:albums => {:except => [:album_artwork]})
from representable.
Nick - After reading through the TODO file, what I think I am after is essentially the representer_options with the ability to use a Proc
or Hash
from representable.
Related Issues (20)
- Using the :skip_parse option with JSON::Hash values produces Pipeline::Stop HOT 1
- XML Encoding? HOT 3
- Populator docs or examples? HOT 4
- XML namespaces
- Options hash passed to setter has incorrect value for collection properties
- Collection parsing raises an error if the value is nil HOT 4
- Document nested inherit: true
- Parsing null values results in property being set despite `reader` property present
- parsing array of arrays
- Bug in dependency package declarative-option update HOT 1
- Nested keys within hash are getting mutated HOT 5
- Custom writer: method is not invoked or not invoked correctly HOT 2
- Can't activate multi_json on (>= 1.14.1), already activated multi_json-1.11.3 HOT 3
- Representable doesn't work as expected on truffleruby-21.3.0 HOT 1
- Nokogiri deprecation warning
- `nested` tries to assign to non-existent property when parsing nil body HOT 7
- Combining nested include/exclude with regular include/exclude HOT 1
- Representing objects into objects using Representable::Object#to_object HOT 8
- Representable 4: problem when parsing looks at one field but wants to create two
- Representable 4: how to collect/write data when parsing?
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 representable.