Class: LiveComponent::SafeDispatcher
- Inherits:
-
Object
- Object
- LiveComponent::SafeDispatcher
- Includes:
- Singleton
- Defined in:
- lib/live_component/safe_dispatcher.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ SafeDispatcher
constructor
A new instance of SafeDispatcher.
- #send_safely(receiver, method_name, **kwargs) ⇒ Object
Constructor Details
#initialize ⇒ SafeDispatcher
Returns a new instance of SafeDispatcher.
11 12 13 |
# File 'lib/live_component/safe_dispatcher.rb', line 11 def initialize @cache = ObjectSpace::WeakKeyMap.new end |
Class Method Details
.send_safely ⇒ Object
28 29 30 |
# File 'lib/live_component/safe_dispatcher.rb', line 28 def self.send_safely(...) instance.send_safely(...) end |
Instance Method Details
#send_safely(receiver, method_name, **kwargs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/live_component/safe_dispatcher.rb', line 15 def send_safely(receiver, method_name, **kwargs) if receiver_defines_safe_method?(receiver, method_name) receiver.send(method_name, **kwargs) else raise( SafeDispatchError, "`#{method_name}' could not be called on an object of type '#{receiver.class.name}'. "\ "Only public methods defined on classes that inherit from ViewComponent::Base "\ "may be called." ) end end |