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 a withOverrides method to ConfigFieldMapping #259

Merged
merged 6 commits into from Jun 9, 2017

Conversation

ruippeixotog
Copy link
Member

Closes #256 and #204.

@melrief
Copy link
Collaborator

melrief commented Jun 3, 2017

Not much to comment, nice and useful addition. Are you planning to add a README part about this somewhere in another PR or you think it's not worth it? I would like to have this somewhere in the README.

@ruippeixotog
Copy link
Member Author

I'll add this to the README later, it is surely useful to have it there.

Copy link
Member

@jcazevedo jcazevedo left a comment

Choose a reason for hiding this comment

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

Looks good to merge without reservations. It's a very helpful addition to the library.

Copy link
Collaborator

@leifwickland leifwickland left a comment

Choose a reason for hiding this comment

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

This is a very nice addition. Thanks, @ruippeixotog.
I made a small suggestion. Take it or leave it.

* uses this mapping.
*/
def withExceptions(exceptions: (String, String)*) = {
val map = exceptions.toMap
Copy link
Collaborator

Choose a reason for hiding this comment

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

A slightly terser take:

ConfigFieldMapping(exceptions.toMap.withDefault(apply))

Copy link
Member Author

Choose a reason for hiding this comment

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

Nicely done, I didn't think of using withDefault here :) Changed the method to your suggestion in 213551c.

/**
* Returns a `ConfigFieldMapping` that uses this mapping with some exceptions.
*
* @param exceptions the exceptions for this mapping as pairs (field, configKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ruippeixotog It might be worth adding a comment explaining that any override will be applied globally throughout the configuration, e.g. if a ("foo", "bar") exception is provided it will affect all fields named foo regardless of which object they're in and will affect all bar config keys regardless of the path leading up to the .bar part.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the distinction between ConfigFieldMapping and a ProductHint provides that information. A ConfigFieldMapping has no type parameter and has no effect as an implicit. On the other hand, a ProductHint has a type parameter restricting the hint to certain types (possibly one or all). Different product hints may be configured with different mappings, so "any override will be applied globally throughout the configuration" isn't entirely accurate. Do you still think it would be better to improve the documentation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This may seem nitpicky, but I wonder about the naming. Exceptions makes me think this will throw Exceptions. Maybe something like name overrides?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ruippeixotog I agree that I was wrong when I said "globally throughout the configuration." I didn't realize the scope that the ConfigFieldMapping was applied within was a ProductHint. (I probably should, but I didn't.)

Probably nothing needs to be added. I'm skeptical I could inform without confusing.

Sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

@leifwickland I understand the confusion, in older pureconfig versions ConfigFieldMapping was the object to provide implicitly to configure product derivation :) Since ProductHints were added, ConfigFieldMapping was made only one of the multiple things you can configure via a ProductHint.

@derekmorr yeah, I wonder about that too. I don't think that the current name is perfect, but I'm not sure if withOverrides isn't less explicit/correct in the context of a mapping... I ended up using withExceptions. @leifwickland, @melrief, @jcazevedo, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ruippeixotog I'd probably go with withOverrides.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer withExceptions. They're effectively exceptions to the general mapping rule. I think any confusion users might have that this will throw exceptions can be dismissed by looking at the method's documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

@melrief, what do you think about this? We need a fifth opinion here :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer overrides. While I agree on the meaning of exception in this case, I also think the name can be confusing. I like override because it can be seen as "override the mapping behavior for the given fields"

Copy link
Member Author

Choose a reason for hiding this comment

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

All right, renamed to withOverrides in 274b3de! :)

@ruippeixotog ruippeixotog changed the title Add a withExceptions method to ConfigFieldMapping Add a withOverrides method to ConfigFieldMapping Jun 9, 2017
@ruippeixotog ruippeixotog merged commit 24e9c84 into master Jun 9, 2017
@ruippeixotog ruippeixotog deleted the field-mapping-exceptions branch June 9, 2017 23:12
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.

None yet

5 participants