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 env #437

Merged
merged 3 commits into from
Oct 11, 2018
Merged

Add env #437

merged 3 commits into from
Oct 11, 2018

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Oct 11, 2018

This PR adds a new env function which helps convert environment types to their respective boolean or int values.

we are currently doing this:

import os
...
DATABASES = {
    'default': {
        'driver': os.environ.get('DB_DRIVER', 'default'),
        'host': os.environ.get('DB_HOST', 'default'),
        'port': os.environ.get('DB_PORT', 'default'),
    }
}

Now we can do this:

from masonite import env
...
DATABASES = {
    'default': {
        'driver': env('DB_DRIVER', 'default'),
        'host': env('DB_HOST', 'default'),
        'port': env('DB_PORT', 'default'),
    }
}

Not only does this shorten things down a bit but it ALSO will type cast as well. So an environment variable of '3306' (string) will actually convert to 3306 (int)

Also an environment variable of 'True' or 'true' will convert to the actual boolean of True

@josephmancuso josephmancuso self-assigned this Oct 11, 2018
@josephmancuso josephmancuso requested a review from a team October 11, 2018 02:59
@coveralls
Copy link

coveralls commented Oct 11, 2018

Coverage Status

Coverage increased (+0.03%) to 91.869% when pulling 968851a on add-env into 40715fb on develop.

@josephmancuso josephmancuso merged commit 267d932 into develop Oct 11, 2018
@josephmancuso
Copy link
Member Author

This actually also solves the problem of 'False' actually being True because it is a string

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

2 participants