Module: Servus::Support::Lockdown
- Included in:
- Base
- Defined in:
- lib/servus/support/lockdown.rb
Overview
Enforces that services are invoked through Base.call rather than by instantiating a service and calling its instance ‘#call` directly. The class-level `.call` runs argument validation, logging, benchmarking, guard handling, result validation, and event emission; calling the instance method directly would silently skip all of that.
When included in Base, this module:
-
Privatizes ‘.new` on the base class (and, by inheritance, on every descendant) so `MyService.new` from outside the class raises `NoMethodError`.
-
Installs a ‘method_added` hook on every descendant that privatizes any instance-level `#call` at definition time.
Controlled by Config#lockdown_enabled (default ‘true`). Set it to `false` to allow direct instantiation and public instance `#call` — useful if you have existing code that relies on those entry points, or if you prefer to opt out of this enforcement entirely.
Defined Under Namespace
Modules: ClassMethods, Inherited, PrivateCall
Class Method Summary collapse
-
.included(base) ⇒ void
private
Wires the lockdown hooks into the including class.
Class Method Details
.included(base) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Wires the lockdown hooks into the including class.
Extends the base with ClassMethods (for Servus::Support::Lockdown::ClassMethods#apply_lockdown!), prepends Inherited so subclasses receive the ‘method_added` hook, and applies the current config value to `.new`’s visibility.
39 40 41 42 43 |
# File 'lib/servus/support/lockdown.rb', line 39 def self.included(base) base.extend(ClassMethods) base.singleton_class.prepend(Inherited) base.apply_lockdown! end |