asana_hub/json_data.py
def apply(self, key, value, prompt=None,
        on_load=lambda a: a, on_save=lambda a: a):
        """Applies a setting value to a key, if the value is not `None`.

        Returns without prompting if either of the following:
            * `value` is not `None`
            * already present in the dictionary

        Args:
            prompt:
                May either be a string to prompt via `raw_input` or a
                method (callable) that returns the value.

            on_load:
                lambda. Value is passed through here after loaded.

            on_save:
                lambda. Value is saved as this value.
        """

        # Reset value if flag exists without value
        if value == '':
            value = None
            if key and self.data.has_key(key): del self.data[key]

        # If value is explicitly set from args.
        if value is not None:
            value = on_load(value)
            if key: self.data[key] = on_save(value)
            return value

        elif not key or not self.has_key(key):
            if callable(prompt):
                value = prompt()
            elif prompt is not None:
                value = raw_input(prompt + ": ")

            if value is None:
                if self.data.has_key(key): del self.data[key]
                return None

            self.data[key] = on_save(value)
            return value

        return on_load(self.data[key])
def apply(self, key, value, prompt=None,
        on_load=lambda a: a, on_save=lambda a: a):
        """Applies a setting value to a key, if the value is not `None`.

        Returns without prompting if either of the following:
            * `value` is not `None`
            * already present in the dictionary

        Args:
            prompt:
                May either be a string to prompt via `raw_input` or a
                method (callable) that returns the value.

            on_load:
                lambda. Value is passed through here after loaded.

            on_save:
                lambda. Value is saved as this value.
        """

        # Reset value if flag exists without value
        if value == '':
            value = None
            if key and self.data.has_key(key): del self.data[key]

        # If value is explicitly set from args.
        if value is not None:
            value = on_load(value)
            if key: self.data[key] = on_save(value)
            return value

        elif not key or not self.has_key(key):
            if callable(prompt):
                value = prompt()
            elif prompt is not None:
                value = raw_input(prompt + ": ")

            if value is None:
                if self.data.has_key(key): del self.data[key]
                return None

            self.data[key] = on_save(value)
            return value

        return on_load(self.data[key])
Applies a setting value to a key, if the value is not `None`.

        Returns without prompting if either of the following:
            * `value` is not `None`
            * already present in the dictionary

        Args:
            prompt:
                May either be a string to prompt via `raw_input` or a
                method (callable) that returns the value.

            on_load:
                lambda. Value is passed through here after loaded.

            on_save:
                lambda. Value is saved as this value.