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

translation should allow to be ignored #79

Closed
Licenser opened this issue Nov 26, 2013 · 12 comments
Closed

translation should allow to be ignored #79

Licenser opened this issue Nov 26, 2013 · 12 comments

Comments

@Licenser
Copy link
Contributor

Basically it is possible to have a mapping not take effect when they are not present, right now there isn't a way to have this behaviour for translations.

A simple way to implement this would to change the return value of translation functions to {ok, Value} or undefined in which case undefined would mean the translation has no effect.

This was referenced Dec 2, 2013
@joedevivo
Copy link
Contributor

@Licenser could you include the real-world example you ran in to?

@Licenser
Copy link
Contributor Author

Licenser commented Dec 3, 2013

  • The mDNS library I use auto detects the NIC to use unless a IP to use is specified in the app.config.
  • The main app will use either a autodetected or a specified IP/Port combination.

In the schema I tried to assing the mdns ip based on weather the ip/port is set, this needed a translation, which should not set anything in the app.config when ip/port is not set.

@joedevivo
Copy link
Contributor

@Licenser Would having the translation return 'undefined' when the IP/Port combination solve the problem?

@Licenser
Copy link
Contributor Author

Licenser commented Dec 3, 2013

Yap, it would turn into {ok, undefined} with the get_env which is different form undefined aside of adding a third fork in the code path it'd break the claim that we can use get_env the same way as before ;)

@joedevivo
Copy link
Contributor

@Licenser what if you used get_env/3 instead of get_env/2?

@Licenser
Copy link
Contributor Author

Licenser commented Dec 3, 2013

Not available in erlang R15 :(, that said in R16 I could put in the code to default to {ok, undefined} but that still would be kind of a horrible hackish solution.

@joedevivo
Copy link
Contributor

So it's no longer 'undefined' it's "defined as undefined"

@Licenser
Copy link
Contributor Author

Licenser commented Dec 3, 2013

yea but get_env treats those two situations differently:

  • if it is undefined get_env(something) returns undefined
  • if it is defined as undefined then get_env(something) returns {ok, undefined}

@joedevivo
Copy link
Contributor

I'll take this scenario under advisement, but for now, your best bet is to add the third clause for reading this value:

{ok, undefined} -> blah;
undefined -> blah;
{ok, Value} -> blah

@Licenser
Copy link
Contributor Author

Licenser commented Dec 3, 2013

To add to this I just thought of another issue, if someone were to use get_env/3 the default would not be picked when the value is set to undefined instead of not being defined at all breaking that behavior and being quite counter intuitive.

@joedevivo
Copy link
Contributor

get_env/3 has it's own issues, use at your own risk ;)

@seancribbs
Copy link
Contributor

@Licenser We now have an API function cuttlefish:unset() which can be used to skip emitting a value to the generated configuration. Closing this issue.

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

No branches or pull requests

3 participants