Class: StimulusPlumbers::Components::Plumber::Dispatcher::InstanceExec
- Inherits:
-
Object
- Object
- StimulusPlumbers::Components::Plumber::Dispatcher::InstanceExec
- Defined in:
- lib/stimulus_plumbers/components/plumber/dispatcher.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(block, *args, **kwargs) ⇒ InstanceExec
constructor
A new instance of InstanceExec.
Constructor Details
#initialize(block, *args, **kwargs) ⇒ InstanceExec
Returns a new instance of InstanceExec.
40 41 42 43 44 45 |
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 40 def initialize(block, *args, **kwargs) @block = block @args = args @kwargs = kwargs validate! end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
38 39 40 |
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 38 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
38 39 40 |
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 38 def block @block end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
38 39 40 |
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 38 def kwargs @kwargs end |
Instance Method Details
#call(target) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stimulus_plumbers/components/plumber/dispatcher.rb', line 47 def call(target) accepts_args = block.arity.negative? ? args : args.take(block.arity) accepts_kwargs = block.parameters.any? { |type, _| %i[key keyreq keyrest].include?(type) } if accepts_kwargs target.instance_exec( *accepts_args, **kwargs, &block ) else target.instance_exec(*accepts_args, &block) end end |