Class: TicketPresenter

Inherits:
Object
  • Object
show all
Includes:
UrlHelper
Defined in:
app/presenters/ticket_presenter.rb

Instance Method Summary collapse

Methods included from UrlHelper

#edit_release_path, #edit_release_url, #feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #release_path, #release_url, #releases_path

Constructor Details

#initialize(tickets) ⇒ TicketPresenter

Returns a new instance of TicketPresenter.



4
5
6
# File 'app/presenters/ticket_presenter.rb', line 4

def initialize(tickets)
  @tickets = OneOrMany.new(tickets)
end

Instance Method Details

#as_json(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'app/presenters/ticket_presenter.rb', line 8

def as_json(*args)
  tickets = @tickets
  tickets = Houston.benchmark "[#{self.class.name.underscore}] Load objects" do
    tickets.load
  end if tickets.is_a?(ActiveRecord::Relation)
  Houston.benchmark "[#{self.class.name.underscore}] Prepare JSON" do
    tickets.map(&method(:ticket_to_json))
  end
end

#ticket_to_json(ticket) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/presenters/ticket_presenter.rb', line 18

def ticket_to_json(ticket)
  project = ticket.project
  { id: ticket.id,
    openedAt: ticket.created_at,
    closedAt: ticket.closed_at,
    projectId: project.id,
    projectSlug: project.slug,
    projectTitle: project.name,
    projectColor: project.color,
    ticketSystem: project.ticket_tracker_name,
    ticketUrl: ticket.ticket_tracker_ticket_url,
    number: ticket.number,
    summary: ticket.summary,
    type: ticket.type.to_s.downcase.dasherize,
    tags: ticket.tags.map(&:to_h),
    extendedAttributes: ticket.extended_attributes }
end