Skip to content

Instantly share code, notes, and snippets.

@marcelolebre
Last active April 30, 2017 22:03
Show Gist options
  • Save marcelolebre/a87d788b578ab2a49e80ad755466af43 to your computer and use it in GitHub Desktop.
Save marcelolebre/a87d788b578ab2a49e80ad755466af43 to your computer and use it in GitHub Desktop.
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