Skip to content

Commit

Permalink
introduce 'ignore_missing' optional parameter to anyconfig.backend.js…
Browse files Browse the repository at this point in the history
…on_.JsonConfigParser.load; it does not simply inherit the parent's method
  • Loading branch information
ssato committed Oct 13, 2014
1 parent 1226ce4 commit 54c55ba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion anyconfig/backend/json_.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ def loads(cls, config_content, **kwargs):
**Base.mk_opt_args(cls._load_opts, kwargs))

@classmethod
def load(cls, config_path, **kwargs):
def load(cls, config_path, ignore_missing=False, **kwargs):
"""
:param config_path: Config file path
:param ignore_missing: Ignore just return empty result if given file
(``config_path``) does not exist
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: cls.container() object holding config parameters
"""
# NOTE: Hack. See also: :method:``load`` of the class
# :class:``anyconfig.backends.Base.ConfigParser``.
if ignore_missing and not cls.exists(config_path):
return cls.container()()

return json.load(open(config_path), object_hook=dict_to_container,
**Base.mk_opt_args(cls._load_opts, kwargs))

Expand Down

0 comments on commit 54c55ba

Please sign in to comment.