Giter Site home page Giter Site logo

Comments (3)

apotonick avatar apotonick commented on June 28, 2024

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.

mpeychich avatar mpeychich commented on June 28, 2024

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.

mpeychich avatar mpeychich commented on June 28, 2024

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)

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.