DEV: Pass kwargs to defined method (#19552)

This commit is contained in:
Bianca Nenciu 2022-12-21 19:02:40 +02:00 committed by GitHub
parent b4b14c4d95
commit 58479fe10b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -281,8 +281,8 @@ class Plugin::Instance
hidden_method_name = :"#{attr}_without_enable_check" hidden_method_name = :"#{attr}_without_enable_check"
klass.public_send(:define_method, hidden_method_name, &block) klass.public_send(:define_method, hidden_method_name, &block)
klass.public_send(:define_method, attr) do |*args| klass.public_send(:define_method, attr) do |*args, **kwargs|
public_send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args, **kwargs) if plugin.enabled?
end end
end end
end end
@ -295,8 +295,8 @@ class Plugin::Instance
hidden_method_name = :"#{attr}_without_enable_check" hidden_method_name = :"#{attr}_without_enable_check"
klass.public_send(:define_singleton_method, hidden_method_name, &block) klass.public_send(:define_singleton_method, hidden_method_name, &block)
klass.public_send(:define_singleton_method, attr) do |*args| klass.public_send(:define_singleton_method, attr) do |*args, **kwargs|
public_send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args, **kwargs) if plugin.enabled?
end end
end end
end end
@ -311,8 +311,8 @@ class Plugin::Instance
hidden_method_name = :"#{method_name}_without_enable_check" hidden_method_name = :"#{method_name}_without_enable_check"
klass.public_send(:define_method, hidden_method_name, &block) klass.public_send(:define_method, hidden_method_name, &block)
klass.public_send(callback, **options) do |*args| klass.public_send(callback, **options) do |*args, **kwargs|
public_send(hidden_method_name, *args) if plugin.enabled? public_send(hidden_method_name, *args, **kwargs) if plugin.enabled?
end end
hidden_method_name hidden_method_name
@ -462,8 +462,8 @@ class Plugin::Instance
# A proxy to `DiscourseEvent.on` which does nothing if the plugin is disabled # A proxy to `DiscourseEvent.on` which does nothing if the plugin is disabled
def on(event_name, &block) def on(event_name, &block)
DiscourseEvent.on(event_name) do |*args| DiscourseEvent.on(event_name) do |*args, **kwargs|
block.call(*args) if enabled? block.call(*args, **kwargs) if enabled?
end end
end end
@ -580,8 +580,8 @@ class Plugin::Instance
def register_html_builder(name, &block) def register_html_builder(name, &block)
plugin = self plugin = self
DiscoursePluginRegistry.register_html_builder(name) do |*args| DiscoursePluginRegistry.register_html_builder(name) do |*args, **kwargs|
block.call(*args) if plugin.enabled? block.call(*args, **kwargs) if plugin.enabled?
end end
end end