Skip to content

Commit

Permalink
better casting process
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 29, 2015
1 parent 31c9fff commit 0a6ef1f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/appier/config.py
Expand Up @@ -41,6 +41,8 @@
import sys
import json

from . import legacy

FILE_NAME = "appier.json"
""" The default name of the file that is going to be
used for the loading of configuration values from json """
Expand Down Expand Up @@ -73,14 +75,16 @@ def conf(name, default = None, cast = None):
:type default: Object
:param default: The default value to be retrieved in case
no value was found for the provided name.
:type cast: Type
:type cast: Type/String
:param cast: The cast operation to be performed in the
resolved value (optional).
:rtype: Object
:return: The value for the configuration with the requested
name or the default value if no value was found.
"""

is_string = type(cast) in legacy.STRINGS
if is_string: cast = __builtins__.get(cast, None)
cast = CASTS.get(cast, cast)
value = CONFIGS.get(name, default)
if cast and not value == None: value = cast(value)
Expand Down

0 comments on commit 0a6ef1f

Please sign in to comment.