Code Monkey home page Code Monkey logo

Comments (6)

nesaulov avatar nesaulov commented on June 29, 2024

@AlessandroMinali @nulldef what do you think would be the best option here?

from surrealist.

nesaulov avatar nesaulov commented on June 29, 2024

Personally I prefer via or format.

from surrealist.

nulldef avatar nulldef commented on June 29, 2024

We can try using for keyword.
format is terrible I think. And about via - maybe It will be more semantically correct in some cases, but not in mostly cases.

from surrealist.

nesaulov avatar nesaulov commented on June 29, 2024

Yes, maybe you are right and for is a good option since the most cases where one would need multiple serializers would be a web application with a number of presentation points of some models. Something like

class Post < ActiveRecord::Base
  include Surrealist
  
  surrealize_with PostSerializer
  surrealize_with PostPreviewSerializer, tag: :preview
  surrealize_with PostApiSerializer, tag: :api
  surrealize_with PostFrontendSerializer, tag: :frontend
end

In this case the most appropriate way to specify serialiser would be to specify the goal of serialization.

Post.find(42).surrealize(for: :preview)
Post.find(42).surrealize(for: :api)
Post.find(42).surrealize(for: :frontend)

Post.find(42).surrealize(via: :preview) doesn't seem quite right in this case. So the question is whether this kind of context would be primary for the most of the use cases of this feature. @AlessandroMinali what do you think?

from surrealist.

AlessandroMinali avatar AlessandroMinali commented on June 29, 2024

:for seems fine to me.

I guess one way to cover all use cases is to be pedantic and just call the option :serializer. That leaves nothing to the imagination and is pretty dry about what is going on/being passed. In that case I'd still argue for :as to set the alias.

If the user sets a tag but then still wants to be explicit and call the actual serializer by the constant are we going to allow that?
i.e.:

Something.new.surrealize(tag: :short)
Something.new.surrealize(tag: SomethingShortSerializer) 

from surrealist.

nesaulov avatar nesaulov commented on June 29, 2024

I guess we will provide the option to specify the serialiser class with
Post.find(42).surrealize(serializer: PostPreviewSerializer). And for symbols let's leave for:
Post.find(42).surrealize(for: :preview)

from surrealist.

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.