Module: RubyZmqFramework::StrictContract::ClassMethods
- Defined in:
- lib/ruby_zmq_framework/framework.rb
Instance Method Summary collapse
-
#new ⇒ Object
The check runs BEFORE super (i.e. before allocate/initialize), so a violating class never gets partially constructed.
- #required_methods ⇒ Object
- #requires_methods(*methods) ⇒ Object
Instance Method Details
#new ⇒ Object
The check runs BEFORE super (i.e. before allocate/initialize), so a violating class never gets partially constructed. This matters for FrameworkModule: its prepended Heartbeat starts a broadcasting thread inside initialize, and checking afterwards would leak that thread from a zombie instance whose .new appeared to fail.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby_zmq_framework/framework.rb', line 22 def new(...) missing = required_methods.reject do |m| method_defined?(m) || private_method_defined?(m) end if missing.any? raise NotImplementedError, "[Framework Error] Contract Violation: #{self} missing #{missing.join(', ')}" end super end |
#required_methods ⇒ Object
12 13 14 15 |
# File 'lib/ruby_zmq_framework/framework.rb', line 12 def required_methods inherited = superclass.respond_to?(:required_methods) ? superclass.required_methods : [] inherited | (@required_methods || []) end |
#requires_methods(*methods) ⇒ Object
8 9 10 |
# File 'lib/ruby_zmq_framework/framework.rb', line 8 def requires_methods(*methods) @required_methods = methods end |