Module: StimulusPlumbers::Components::Plumber::Dispatcher

Defined in:
lib/stimulus_plumbers/components/plumber/dispatcher.rb

Defined Under Namespace

Classes: InstanceExec, KlassProxy, MethodCall

Class Method Summary collapse

Class Method Details

.build(callable, *args, method_name: nil, init_args: [], init_kwargs: {}, **kwargs) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 95

def self.build(callable, *args, method_name: nil, init_args: [], init_kwargs: {}, **kwargs)
  case callable
  when Symbol
    MethodCall.new(callable, *args, **kwargs)
  when Proc
    InstanceExec.new(callable, *args, **kwargs)
  when Module
    KlassProxy.new(callable, method_name, *args, init_args: init_args, init_kwargs: init_kwargs, **kwargs)
  when String
    klass = callable.safe_constantize
    raise ArgumentError, "could not resolve class from: #{callable.inspect}" unless klass

    KlassProxy.new(klass, method_name, *args, init_args: init_args, init_kwargs: init_kwargs, **kwargs)
  end
end