summaryrefslogtreecommitdiff
path: root/app/serializers/analytics_issue_entity.rb
blob: a0d6d120a484638b060079542949fe51e6fd0975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

class AnalyticsIssueEntity < Grape::Entity
  include RequestAwareEntity
  include EntityDateHelper

  expose :title
  expose :author, using: UserEntity
  expose :project_path do |object|
    object[:project_path]
  end

  expose :namespace_full_path do |object|
    object[:namespace_path]
  end

  expose :iid do |object|
    object[:iid].to_s
  end

  expose :total_time do |object|
    distance_of_time_as_hash(object[:total_time].to_f)
  end

  expose(:created_at) do |object|
    interval_in_words(object[:created_at])
  end

  expose :url do |object|
    url_to(:namespace_project_issue, object)
  end

  private

  def url_to(route, object)
    public_send("#{route}_url", object[:namespace_path], object[:project_path], object[:iid].to_s) # rubocop:disable GitlabSecurity/PublicSend
  end
end