Class: Hyraft::Port
- Inherits:
-
Object
- Object
- Hyraft::Port
- Defined in:
- lib/hyraft/circuit/port.rb
Overview
Port is the base class for all ports in Hexagonal Architecture. It provides contract validation and method introspection for ports.
Direct Known Subclasses
Class Method Summary collapse
-
.all ⇒ Array<Class>
Get all defined ports.
-
.inherited(klass) ⇒ Array
Track all ports that inherit from this class.
-
.validate_implementation(klass) ⇒ Boolean
Validate that a class implements all port methods.
Instance Method Summary collapse
-
#implements?(method_name) ⇒ Boolean
Check if a method is implemented in the port.
-
#inspect ⇒ String
Inspect port with its required methods.
-
#required_methods ⇒ Array<Symbol>
Get all required methods from this port.
-
#validate! ⇒ Boolean
Ruby 4 - Pattern matching for port validation.
Class Method Details
.all ⇒ Array<Class>
Get all defined ports
47 48 49 |
# File 'lib/hyraft/circuit/port.rb', line 47 def all @ports ||= [] end |
.inherited(klass) ⇒ Array
Track all ports that inherit from this class
39 40 41 42 |
# File 'lib/hyraft/circuit/port.rb', line 39 def inherited(klass) @ports ||= [] @ports << klass end |
.validate_implementation(klass) ⇒ Boolean
Validate that a class implements all port methods
90 91 92 93 94 95 96 |
# File 'lib/hyraft/circuit/port.rb', line 90 def self.validate_implementation(klass) missing = instance_methods(false) - klass.instance_methods(false) if missing.any? raise "Class #{klass} must implement: #{missing.join(', ')}" end true end |
Instance Method Details
#implements?(method_name) ⇒ Boolean
Check if a method is implemented in the port
61 62 63 |
# File 'lib/hyraft/circuit/port.rb', line 61 def implements?(method_name) self.class.instance_methods(false).include?(method_name) end |
#inspect ⇒ String
Inspect port with its required methods
114 |
# File 'lib/hyraft/circuit/port.rb', line 114 def inspect = "#<#{self.class.name} methods=#{required_methods}>" |
#required_methods ⇒ Array<Symbol>
Get all required methods from this port
72 73 74 |
# File 'lib/hyraft/circuit/port.rb', line 72 def required_methods self.class.instance_methods(false) end |
#validate! ⇒ Boolean
Ruby 4 - Pattern matching for port validation
101 102 103 104 105 106 |
# File 'lib/hyraft/circuit/port.rb', line 101 def validate! case self in {required_methods: []} then true else true end end |