Class: Ea::Svg::EaEmitter::Marker::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/marker/registry.rb

Overview

Dispatches a connector to the first registered Kind that handles its effective type. New kinds are added by calling Registry.register(MyKind) — no modification of existing code required (OCP).

Defined Under Namespace

Classes: Spec

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.kindsObject (readonly)

Returns the value of attribute kinds.



15
16
17
# File 'lib/ea/svg/ea_emitter/marker/registry.rb', line 15

def kinds
  @kinds
end

Class Method Details

.register(kind) ⇒ Object



17
18
19
# File 'lib/ea/svg/ea_emitter/marker/registry.rb', line 17

def register(kind)
  @kinds << kind
end

.specs_for(connector, effective_type, source, target, before_target, after_source, relationship: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ea/svg/ea_emitter/marker/registry.rb', line 21

def specs_for(connector, effective_type, source, target,
              before_target, after_source, relationship: nil)
  # Lazy: ensure built-in markers are registered on first
  # query. The Marker module's autoload declaration means
  # the marker files only load when referenced.
  Marker.ensure_builtins_registered! if defined?(Marker)
  kind = @kinds.find { |k| k.handles?(effective_type) }
  return [] unless kind

  kind.specs_for(connector, source, target, before_target,
                 after_source, relationship: relationship)
end