Refactor suggestion for ee/app/services/ee/service_ping/build_payload_service.rb
I think the current implementation is fine. I'd suggest simplifying the code a bit with tap
:
def collect_permitted_categories
[STANDARD_CATEGORY, SUBSCRIPTION_CATEGORY].tap do |categories|
categories << OPTIONAL_CATEGORY if ::Gitlab::CurrentSettings.usage_ping_enabled?
categories << OPERATIONAL_CATEGORY if ::License.current.usage_ping?
end
end
We can also combine permitted_categories
with collect_permitted_categories
:
def permitted_categories
@permitted_categories ||= begin
[STANDARD_CATEGORY, SUBSCRIPTION_CATEGORY].tap do |categories|
categories << OPTIONAL_CATEGORY if ::Gitlab::CurrentSettings.usage_ping_enabled?
categories << OPERATIONAL_CATEGORY if ::License.current.usage_ping?
end
end
end