Module: StimulusPlumbers::Plumber::Dispatcher

Defined in:
lib/stimulus_plumbers/plumber/dispatcher.rb,
lib/stimulus_plumbers/plumber/dispatcher/klass_proxy.rb,
lib/stimulus_plumbers/plumber/dispatcher/method_call.rb,
lib/stimulus_plumbers/plumber/dispatcher/instance_exec.rb,
lib/stimulus_plumbers/plumber/dispatcher/callable_inspector.rb

Defined Under Namespace

Modules: CallableInspector Classes: InstanceExec, KlassProxy, MethodCall

Class Method Summary collapse

Class Method Details

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 11

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