Class: StimulusPlumbers::Plumber::Dispatcher::MethodCall

Inherits:
Object
  • Object
show all
Includes:
CallableInspector
Defined in:
lib/stimulus_plumbers/plumber/dispatcher/method_call.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, *args, **kwargs) ⇒ MethodCall

Returns a new instance of MethodCall.



11
12
13
14
15
16
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 11

def initialize(method_name, *args, **kwargs)
  @method_name = method_name
  @args        = args
  @kwargs      = kwargs
  validate!
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9

def args
  @args
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



9
10
11
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9

def kwargs
  @kwargs
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



9
10
11
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9

def method_name
  @method_name
end

Instance Method Details

#call(target) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
21
22
23
24
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 18

def call(target)
  raise NotImplementedError, "#{method_name.inspect} not implemented" unless target.respond_to?(method_name, true)

  method_call = target.method(method_name)
  dispatched  = args_for(method_call)
  accepts_kwargs?(method_call) ? method_call.call(*dispatched, **kwargs) : method_call.call(*dispatched)
end