debian-mirror-gitlab/lib/api/entities/issuable_entity.rb
2020-03-13 15:44:24 +05:30

18 lines
594 B
Ruby

# frozen_string_literal: true
module API
module Entities
class IssuableEntity < Grape::Entity
expose :id, :iid
expose(:project_id) { |entity| entity&.project.try(:id) }
expose :title, :description
expose :state, :created_at, :updated_at
# Avoids an N+1 query when metadata is included
def issuable_metadata(subject, options, method, args = nil)
cached_subject = options.dig(:issuable_metadata, subject.id)
(cached_subject || subject).public_send(method, *args) # rubocop: disable GitlabSecurity/PublicSend
end
end
end
end