Class: Hecks::Bluebook::Entity

Inherits:
Object
  • Object
show all
Extended by:
Behaviour::Entity, Construct, IR
Defined in:
lib/hecks/bluebook/entity.rb

Overview

An entity, as a RUBY CLASS — a piece of an aggregate that has an identity of its own.

Crossing over closes the OWNER CHAIN. An entity declares commands, and until now those commands had no owner that could state an identity: an entity was an IR object, not a construct, so Construct#hecks_fqn refused rather than answering "Deposit" and looking right. Four of banking's commands were in that state. They can say what they are now — Banking::Account.Ledger.Deposit — which is the id the judge already mints for them.

NOT const_set, for the same reason a command is not: a name inside one aggregate can denote more than one kind of thing, so the constant tree cannot index it.

It must stay STRUCTURALLY INTERCHANGEABLE with an aggregate — the runtime builds Instance.new(aggregate: entity) and CommandRules takes either as declaring — so it answers hecks_name, attributes, attribute, identified_by and lifecycle exactly as an aggregate does. And it must keep NOT answering value_object: Value.for_attribute sniffs for that method to tell a piece from a head.

Class Attribute Summary collapse

Attributes included from Construct

#hecks_name, #hecks_owner, #hecks_root

Class Method Summary collapse

Methods included from Construct

hecks_fqn, hecks_root?, hecks_separator

Methods included from IR

extended, included

Methods included from Behaviour::Entity

entities, index_declarations, settle, stamp_children

Methods included from Behaviour::Owns

#stamp

Methods included from Behaviour::Indexed

#attribute, #command, #index_attributes, #index_by_hecks_name, #query

Methods included from Behaviour::Identified

#derive_identity

Class Attribute Details

.attributesObject (readonly)

Returns the value of attribute attributes.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def attributes
  @attributes
end

.commandsObject (readonly)

Returns the value of attribute commands.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def commands
  @commands
end

.descriptionObject (readonly)

Returns the value of attribute description.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def description
  @description
end

.entitiesObject (readonly)

Returns the value of attribute entities.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def entities
  @entities
end

.identified_byObject (readonly)

Returns the value of attribute identified_by.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def identified_by
  @identified_by
end

.identity_headsObject (readonly)

Returns the value of attribute identity_heads.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def identity_heads
  @identity_heads
end

.identity_pathsObject (readonly)

Returns the value of attribute identity_paths.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def identity_paths
  @identity_paths
end

.invariantsObject (readonly)

Returns the value of attribute invariants.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def invariants
  @invariants
end

.lifecycleObject (readonly)

Returns the value of attribute lifecycle.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def lifecycle
  @lifecycle
end

.preconditionsObject (readonly)

Returns the value of attribute preconditions.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def preconditions
  @preconditions
end

.queriesObject (readonly)

Returns the value of attribute queries.



69
70
71
# File 'lib/hecks/bluebook/entity.rb', line 69

def queries
  @queries
end

Class Method Details

.absorb(description:, identified_by:, attributes:, commands:, queries:, entities:, preconditions:, invariants:, lifecycle:) ⇒ Object

Assigns what the language declares, then hands off to the behaviour's own settle — derived identity and the name indexes, neither of which the declaration states.



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/hecks/bluebook/entity.rb', line 87

def absorb(description:, identified_by:, attributes:, commands:, queries:, entities:, preconditions:, invariants:, lifecycle:)
  @description    = description
  @identified_by  = identified_by
  @attributes     = attributes
  @commands       = commands
  @queries        = queries
  @entities       = entities
  @preconditions  = preconditions
  @invariants     = invariants
  @lifecycle      = lifecycle

  settle
end

.declare(name:, description: nil, identified_by: nil, attributes: [], commands: [], queries: [], entities: [], preconditions: [], invariants: [], lifecycle: nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hecks/bluebook/entity.rb', line 72

def declare(name:, description: nil, identified_by: nil, attributes: [],
            commands: [], queries: [], entities: [], preconditions: [], invariants: [], lifecycle: nil)
  piece = Class.new(self)
  piece.hecks_name = name.to_s
  piece.absorb(description: description, identified_by: identified_by,
               attributes: attributes, commands: commands,
               queries: queries, entities: entities, preconditions: preconditions,
               invariants: invariants, lifecycle: lifecycle)
  piece.stamp_children
  piece
end