Module: Hecks::Construct

Overview

The invisible field a built construct carries.

A construct is a RECORD WITH AN OWNER CHAIN — the chapter (Bluebook) owns its aggregates, an aggregate owns everything declared on it — and the bluebook identity is carried in its own field, under a hecks_ prefix that no domain attribute can collide with. Invisible means exactly that: not an attribute, not a key in to_h, not a reader on instances. Framework metadata about the construct, not part of the domain it describes.

The identity is COMPUTED by walking owners rather than stamped, so nothing has to be re-stamped when a chapter is assembled after its aggregates:

Pizzas                     the chapter — no owner
Pizzas::Pizza              an aggregate joins its chapter with ::
Pizzas::Pizza.Price        everything else joins its owner with .

That spelling is not invented here. It is the id MetaValidator::Judge already mints in #identify, so a construct and the meta-domain's record OF that construct carry the same identity, and there is no translation table between them to be quietly wrong in.

Usage:

price = Class.new(ValueObject)   # a declaration holder
price.hecks_name  = "Price"
price.hecks_owner = pizza_ir         # the Aggregate that declares it
price.hecks_fqn                      # => "Pizzas::Pizza.Price"

Defined Under Namespace

Classes: Unowned

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hecks_nameObject

The name as the bluebook declares it, never the constant path.



47
# File 'lib/hecks/construct.rb', line 47

def hecks_name = @hecks_name

#hecks_ownerObject

What declares this one — the chapter above an aggregate, the aggregate above a value object. nil for a chapter, which is the top.



35
36
37
# File 'lib/hecks/construct.rb', line 35

def hecks_owner
  @hecks_owner
end

#hecks_root=(value) ⇒ Object (writeonly)

A chapter is the only construct that legitimately has no owner. Everything else is DECLARED IN something, so a missing owner is an unstamped construct rather than a top — see hecks_fqn.



42
43
44
# File 'lib/hecks/construct.rb', line 42

def hecks_root=(value)
  @hecks_root = value
end

Instance Method Details

#hecks_fqnObject

REFUSES rather than guesses. A construct with no owner and no claim to be a chapter has simply not been stamped yet — entity commands are in that state while entities are still IR objects — and answering the bare name would be a plausible half-truth that no test would notice. That shape of falsehood is what this repo keeps finding, so it goes red instead.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hecks/construct.rb', line 59

def hecks_fqn
  return hecks_name.to_s if hecks_root?

  unless hecks_owner
    raise Construct::Unowned,
          "#{hecks_name.inspect} cannot say what declares it, so it has no " \
          "identity — it was never stamped with an owner"
  end

  "#{hecks_owner.hecks_fqn}#{hecks_separator}#{hecks_name}"
end

#hecks_root?Boolean

Returns:

  • (Boolean)


44
# File 'lib/hecks/construct.rb', line 44

def hecks_root? = @hecks_root ? true : false

#hecks_separatorObject

How this construct joins its owner. An aggregate is a member of its chapter's namespace (::) ; everything else is declared ON its owner (.). Overridden by Aggregate, defaulted here for every other construct.



52
# File 'lib/hecks/construct.rb', line 52

def hecks_separator = "."