This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Based on Ruby Gem by NoFlopSquad (https://github.com/noflopsquad/value-object)

Installation

> pip install simple-value-object

Usage

Constructor and field readers

from simple_value_object import ValueObject

class Point(ValueObject):
    def __init__(self, x, y):
        pass

point = Point(1, 2)

point.x
# 1

point.y
# 2

point.x = 5
# CannotBeChangeException: You cannot change values from a Value Object, create a new one

class Date(ValueObject):
    def __init__(self, day, month, year):
        pass

date = Date(1, 10, 2015)

date.day
# 1

date.month
# 10

date.year
# 2015

date.month = 5
# CannotBeChangeException: You cannot change values from a Value Object, create a new one

Equality based on field values

from simple_value_object import ValueObject

class Point(ValueObject):
    def __init__(self, x, y):
        pass

a_point = Point(5, 3)

same_point = Point(5, 3)

a_point == same_point
# True

a_different_point = Point(6, 3)

a_point == a_different_point
# False

Hash code based on field values

from simple_value_object import ValueObject

class Point(ValueObject):
    def __init__(self, x, y):
        pass

a_point = Point(5, 3)

same_point = Point(5, 3)

a_point.hash == same_point.hash
# True

a_different_point = Point.new(6, 3)

a_point.hash == a_different_point.hash
# False

Invariants

from simple_value_object import ValueObject, invariant

class Point(ValueObject):

    def __init__(self, x, y):
        pass

    @invariant
    def inside_first_quadrant(cls, instance):
        return instance.x > 0 and instance.y > 0

    @invariant
    def x_less_than_y(cls, instance):
        return instance.x < instance.y

Point(-5, 3)
#ViolatedInvariantException: Args values [-5, 3] violates invariant: inside_first_cuadrant

Point(6, 3)
#ViolatedInvariantException: Args values [6, 3] violates invariant: x_less_than_y

Point(1,3)
#<__main__.Point at 0x7f2bd043c780>

Test

> pip install -r requirements-test.txt
> PYTHONPATH=$PYTHONPATH:. mamba
Release History

Release History

0.2.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
simple-value-object-0.2.1.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Oct 5, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting