Class: Sequent::Core::ValueObject
- Inherits:
-
Object
- Object
- Sequent::Core::ValueObject
- 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
-
#initialize(args = {}) ⇒ ValueObject
constructor
A new instance of ValueObject.
Methods included from Helpers::TypeConversionSupport
Methods included from Helpers::StringSupport
Methods included from Helpers::EqualSupport
Methods included from Helpers::Copyable
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 |