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

Add BitcrowdEcto.Changeset.auto_cast/3 #55

Merged
merged 7 commits into from
Dec 20, 2023
Merged

Conversation

maltoe
Copy link
Contributor

@maltoe maltoe commented Dec 20, 2023

This patch consolidates some versions of automatic casting we had flying around. This version features casting scalars & embeds as well as required validations based on :required or :optional options.

Additionally, this adds BitcrowdEcto.Assertions.assert_cast_error_on/2.

This patch consolidates some versions of automatic casting we had flying
around. This version features casting scalars & embeds as well as
required validations based on `:required` or `:optional` options.

Additionally, this adds `BitcrowdEcto.Assertions.assert_cast_error_on/2`.
Copy link
Contributor

@ammancilla ammancilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice function. I can imagine a couple of use cases for this but what's the use case you had in mind?

Left a blocker. More than requesting changes is an question.

lib/bitcrowd_ecto/changeset.ex Outdated Show resolved Hide resolved
lib/bitcrowd_ecto/changeset.ex Show resolved Hide resolved
@maltoe
Copy link
Contributor Author

maltoe commented Dec 20, 2023

Nice function. I can imagine a couple of use cases for this but what's the use case you had in mind?

Use-case is documented here https://bitcrowd.atlassian.net/browse/SIS-4357, but the code originated in another project and has existed in some variant in all our PDF/mail apps for ages.

@ammancilla
Copy link
Contributor

Nice function. I can imagine a couple of use cases for this but what's the use case you had in mind?

Use-case is documented here https://bitcrowd.atlassian.net/browse/SIS-4357, but the code originated in another project and has existed in some variant in all our PDF/mail apps for ages.

I see, thanks for the reference. I am not a big fan of the auto_ prefix in the function since I don't see the "auto" in the implementation itself, it is just plain casting (less powerful than the Ecto.Changeset one but still). I would vote for removing the auto_ (not a strong opinion)

@maltoe
Copy link
Contributor Author

maltoe commented Dec 20, 2023

Nice function. I can imagine a couple of use cases for this but what's the use case you had in mind?

Use-case is documented here https://bitcrowd.atlassian.net/browse/SIS-4357, but the code originated in another project and has existed in some variant in all our PDF/mail apps for ages.

I see, thanks for the reference. I am not a big fan of the auto_ prefix in the function since I don't see the "auto" in the implementation itself, it is just plain casting (less powerful than the Ecto.Changeset one but still). I would vote for removing the auto_ (not a strong opinion)

Open for other names, but just cast conflicts with Ecto.Changeset and client modules are likely to import both (in fact, BitcrowdEcto.Schema users do that automatically).

I thought auto_ because it's automatically figuring out the fields. How about inflect_cast?

@ammancilla
Copy link
Contributor

Nice function. I can imagine a couple of use cases for this but what's the use case you had in mind?

Use-case is documented here https://bitcrowd.atlassian.net/browse/SIS-4357, but the code originated in another project and has existed in some variant in all our PDF/mail apps for ages.

I see, thanks for the reference. I am not a big fan of the auto_ prefix in the function since I don't see the "auto" in the implementation itself, it is just plain casting (less powerful than the Ecto.Changeset one but still). I would vote for removing the auto_ (not a strong opinion)

Open for other names, but just cast conflicts with Ecto.Changeset and client modules are likely to import both (in fact, BitcrowdEcto.Schema users do that automatically).

I thought auto_ because it's automatically figuring out the fields. How about inflect_cast?

Sounds good, either that or apply_cast as well.

@maltoe
Copy link
Contributor Author

maltoe commented Dec 20, 2023

renamed to cast_all @ammancilla

@maltoe maltoe merged commit a8dd426 into main Dec 20, 2023
1 check passed
@maltoe maltoe deleted the add-changeset-auto-cast branch December 20, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants