Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL for serializer contexts #67

Closed
nesaulov opened this issue Feb 3, 2018 · 4 comments
Closed

DSL for serializer contexts #67

nesaulov opened this issue Feb 3, 2018 · 4 comments

Comments

@nesaulov
Copy link
Owner

nesaulov commented Feb 3, 2018

As @AlessandroMinali suggested in #61:

Maybe this could be another DSL (at the cost of adding more complexity for a low use case, maybe not worth)?

Right now we have to access context variables via context[:variable_name]. Suggested is the following DSL:

class IncomeSerializer < Surrealist::Serializer
  json_schema { { amount: Integer } }
  serializer_context :current_user, :something, :else
  
  def amount
    current_user.guest? ? 100000000 : object.amount
  end
end

I suggest to implement this feature (if we decide to implement it in the first place) after 1.0.

@nulldef nulldef closed this as completed Feb 11, 2018
@nulldef nulldef reopened this Feb 11, 2018
@nulldef
Copy link
Collaborator

nulldef commented Feb 11, 2018

Sorry, my mistake )

@nulldef
Copy link
Collaborator

nulldef commented Feb 11, 2018

It seems not cool, here we write json_schema, there - serializer_context. Maybe we should use json_context?

@AlessandroMinali
Copy link
Collaborator

I think that still gets the point across, I don't feel strongly about either. Should we add an method alias here as well for a plural version :json_contexts to be dev friendly?

@nesaulov
Copy link
Owner Author

I think that json_context is a bit misleading here. It's a context which is available inside a serializer instance, not inside JSON object. I am with the plural version idea though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants