Class: Hecks::Bluebook::DSL::DomainPortBuilder

Inherits:
Object
  • Object
show all
Includes:
WordGate
Defined in:
lib/hecks/bluebook/dsl/domain_port_builder.rb

Constant Summary collapse

GRAMMAR_CONTEXT =
"DomainPort"

Constants included from WordGate

WordGate::NOT_ADMITTED

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, owner: nil) ⇒ DomainPortBuilder

Returns a new instance of DomainPortBuilder.



10
11
12
13
14
# File 'lib/hecks/bluebook/dsl/domain_port_builder.rb', line 10

def initialize(name, owner: nil)
  @name       = name
  @owner      = owner
  @operations = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hecks::Bluebook::DSL::WordGate

Class Method Details

.build(name, owner: nil, &block) ⇒ Object



71
72
73
74
75
# File 'lib/hecks/bluebook/dsl/domain_port_builder.rb', line 71

def self.build(name, owner: nil, &block)
  builder = new(name, owner: owner)
  builder.instance_eval(&block) if block
  builder.build
end

Instance Method Details

#asks_impl(name, to: nil, &block) ⇒ Object

WHAT WE ASK OF THE OUTSIDE — the direction this language did not have. Before this, a domain could be CALLED by an adapter and never call one. An asks is dispatched like any other port operation, so a policy can trigger it off an event, and it comes back as one of the two events it named — which is what makes the outside world something the model can reason about rather than a place exceptions come from.

RENAMED FROM asks — item #13's full metaprogrammed dispatch (slice 4c), same reasoning as tells_impl above.



42
43
44
# File 'lib/hecks/bluebook/dsl/domain_port_builder.rb', line 42

def asks_impl(name, to: nil, &block)
  @operations << PortOperationBuilder.build(name, to: to, owner: @owner, direction: :outbound, &block)
end

#buildObject

THE DRIVEN HALF OF THE SAME WORD. operation/emits translates an inbound fact into this domain's own event vocabulary — there is no channel back to a caller beyond the events it emits. verb is the opposite direction: the domain calling OUT to a swappable adapter and getting a real value back (a checkout URL, a fetched document), exactly what Hecks.port "name" do verb "x" end already builds — this is that same Port, reached from the same port call operation already lives under, so a project's own resource ports read next to their binding instead of in a separate file. One port, one shape or the other — never both. verb — item #13's full metaprogrammed dispatch, slice 1 (whole-project table-unification survey): a bare, kind-driven coerce-and-assign with nothing else, now executed by GenericDispatch.

Raises:



61
62
63
64
65
66
67
68
69
# File 'lib/hecks/bluebook/dsl/domain_port_builder.rb', line 61

def build
  raise Malformed, "#{@name} declares both a verb and operations — a port is one or the other, not both" if @verb && !@operations.empty?

  return Port.new(name: @name, verb: @verb, signal: :reply) if @verb

  raise Malformed, "#{@name} declares no verb and no operations" if @operations.empty?

  DomainPort.new(name: @name, operations: @operations)
end

#tells_impl(name, to: nil, &block) ⇒ Object

WHAT THE OUTSIDE TELLS US — an external fact arriving, translated into this domain's own word for it. Spelled operation before it had a twin, and operation still works: the corpus is full of it, and renaming a word costs every chapter that uses it for no gain a reader can feel.

RENAMED FROM tells — item #13's full metaprogrammed dispatch (slice 4c). operation/tells are TWO separate Keyword rows (a word admitting two forms) that both name calls: "tells_impl" — the routing between the two spellings now lives in the table, not in a Ruby alias. Not bootstrap-reachable (checked directly), so no BOOTSTRAP_CALLS_FALLBACK entry needed.



28
29
30
# File 'lib/hecks/bluebook/dsl/domain_port_builder.rb', line 28

def tells_impl(name, to: nil, &block)
  @operations << PortOperationBuilder.build(name, to: to, owner: @owner, direction: :inbound, &block)
end