debian-mirror-gitlab/app/services/concerns/work_items/widgetable_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
973 B
Ruby
Raw Normal View History

2022-08-13 15:12:31 +05:30
# frozen_string_literal: true
module WorkItems
module WidgetableService
2022-11-25 23:54:43 +05:30
def execute_widgets(work_item:, callback:, widget_params: {}, service_params: {})
2022-08-13 15:12:31 +05:30
work_item.widgets.each do |widget|
2022-11-25 23:54:43 +05:30
widget_service(widget, service_params).try(callback, params: widget_params[widget.class.api_symbol])
2022-08-13 15:12:31 +05:30
end
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
2022-11-25 23:54:43 +05:30
def widget_service(widget, service_params)
2022-08-13 15:12:31 +05:30
@widget_services ||= {}
return @widget_services[widget] if @widget_services.has_key?(widget)
2022-11-25 23:54:43 +05:30
@widget_services[widget] = widget_service_class(widget)&.new(
widget: widget,
current_user: current_user,
service_params: service_params
)
2022-08-13 15:12:31 +05:30
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def widget_service_class(widget)
2022-08-27 11:52:29 +05:30
"WorkItems::Widgets::#{widget.type.to_s.camelize}Service::#{self.class.name.demodulize}".constantize
2022-08-13 15:12:31 +05:30
rescue NameError
nil
end
end
end