Last active
April 30, 2017 22:03
-
-
Save marcelolebre/a87d788b578ab2a49e80ad755466af43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ValueComposite(object): | |
def initialize(self, raw_value): | |
self._raw_value = raw_value | |
# Serializer methods for dict based value objects (initialized with {}) | |
def serialize_with(self, **entry): | |
self._raw_value.update(entry) | |
def serialize_from_value(self, value): | |
self._raw_value.update(value.raw) | |
# Serializer methods for array based value objects (initialized with []) | |
def serialize_and_append(self, entry): | |
self._raw_value.append(entry) | |
def serialize_and_append_from_value(self, value): | |
self._raw_value.append(value.raw) | |
def serialize_and_append_from_values(self, values): | |
self._raw_value += map(lambda value: value.raw, values) | |
@property | |
def raw(self): | |
return self._raw_value | |
def json(self): | |
return json.dumps(self._raw_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment