Class: Sequent::Core::ValueObject

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Helpers::AttributeSupport, Helpers::Copyable, Helpers::EqualSupport, Helpers::ParamSupport, Helpers::StringSupport, Helpers::TypeConversionSupport
Defined in:
lib/sequent/core/value_object.rb

Overview

ValueObject is a container for data that belongs together but requires no identity

If something requires identity is up to you to decide. An example in for instance the invoicing domain could be a person’s Address.

class Address < Sequent::Core::ValueObject
  attrs street: String, city: String, country: Country
end

A ValueObject is equal to another ValueObject if and only if all attrs are equal.

You can copy a valueobject as follows:

new_address = address.copy(street: "New Street")

This a deep clone of the address with the street attribute containing “New Street”

Instance Method Summary collapse

Methods included from Helpers::TypeConversionSupport

#parse_attrs_to_correct_types

Methods included from Helpers::StringSupport

#to_s

Methods included from Helpers::EqualSupport

#==, #eql?, #hash

Methods included from Helpers::Copyable

#copy

Methods included from Helpers::AttributeSupport

#as_json, #attributes, #ensure_known_attributes, included, #update, #validation_errors

Methods included from Helpers::ParamSupport

#as_params, #from_params, included, #to_params

Constructor Details

#initialize(args = {}) ⇒ ValueObject

Returns a new instance of ValueObject.



38
39
40
# File 'lib/sequent/core/value_object.rb', line 38

def initialize(args = {})
  update_all_attributes args
end