fakedata icon indicating copy to clipboard operation
fakedata copied to clipboard

Reading the generator from environment?

Open kindaro opened this issue 4 years ago • 4 comments

Currently, the value of the deterministic generator is nailed down in FakerSettings. It is used in the function generateWithSettings.

I propose that this function checks if:

  • A certain environment variable is set.
  • It parses to a number.
  • The value of the generator in the given settings is default.
  • The mode of generation is deterministic.

— And if all are true, the value of the parsed environment variable is used as the generator instead of the default value.

The goal is to make it possible to adjust the generator in a convenient way. Of course there are already ways to adjust the generator, but they all require passing it around the code one way or another, which is rather inconvenient.

This change is conservative and backwards compatible. I can write the code and make a pull request.

kindaro avatar Mar 20 '21 10:03 kindaro

Sounds interesting. What do you think about introducing a new function instead which has the above behaviour you describe:

generateWithEnvSettings :: FakerSettings -> Fake a -> IO a

I'm slightly concerned about the additional IO done for each call to generateWithSettings. What do you think ?

psibi avatar Mar 20 '21 13:03 psibi

This is a valid concern. I have not measured the cost of access to environment variables — I imagine it to be small but who knows. On the other hand, introducing this new function will result in some code duplication — I cannot see a way to express any one of generateWithSettings and generateWithEnvSettings in terms of the other. Whichever works for you is fine by me!

kindaro avatar Mar 20 '21 16:03 kindaro

On the other hand, introducing this new function will result in some code duplication — I cannot see a way to express any one of generateWithSettings and generateWithEnvSettings in terms of the other.

I guess that's fine. :-)

psibi avatar Mar 20 '21 16:03 psibi

Alright then, I shall do this within a few days.

kindaro avatar Mar 20 '21 17:03 kindaro