Module: Hecks::Bluebook::Behaviour::ValueObject
- Included in:
- ValueObject
- Defined in:
- lib/hecks/bluebook/behaviour/value_object.rb
Overview
WHAT A VALUE OBJECT DOES. EXTENDED, not included — a value object
is a CLASS (Class.new(self), one per declared shape), so its
behaviour is singleton behaviour, and the holding half's absorb
is what a generated constructor would be.
Instance Method Summary collapse
- #attribute(named) ⇒ Object
-
#closed_set? ⇒ Boolean
A one_of DECLARED but left empty used to be indistinguishable from no one_of at all — both are
members: []— so the rule about it could only live in the builder. -
#sole_attribute ⇒ Object
A single-attribute value object (EmailAddressaddress, CustomerNumbervalue) is a NAME for a scalar, not a genuine group — [[feedback_name_the_scalar_field]].
Instance Method Details
#attribute(named) ⇒ Object
16 |
# File 'lib/hecks/bluebook/behaviour/value_object.rb', line 16 def attribute(named) = attributes.find { |held| held.name == named.to_sym } |
#closed_set? ⇒ Boolean
A one_of DECLARED but left empty used to be indistinguishable from no
one_of at all — both are members: [] — so the rule about it could
only live in the builder. Recording the declaration lets the language
judge it, the same way an empty attribute NAME survives into the IR
and is judged there.
14 |
# File 'lib/hecks/bluebook/behaviour/value_object.rb', line 14 def closed_set? = @closed_set |
#sole_attribute ⇒ Object
A single-attribute value object (EmailAddressaddress,
CustomerNumbervalue) is a NAME for a scalar, not a genuine
group — [[feedback_name_the_scalar_field]]. Four call sites
already inline this exact check (attributes.size == 1 /
attributes.first) — forms/field_shape.rb (twice),
adapters/driven/sql_query_builder.rb,
fuzzing/invalid_value_generator.rb — kept as-is for now
(not migrated to this reader), but any NEW caller should
reach for this rather than add a fifth inline copy.
27 28 29 |
# File 'lib/hecks/bluebook/behaviour/value_object.rb', line 27 def sole_attribute attributes.first if attributes.size == 1 end |