Class: TaskPresenter

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

Direct Known Subclasses

SprintTaskPresenter

Instance Attribute Summary collapse

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(tasks) ⇒ TaskPresenter

Returns a new instance of TaskPresenter.



6
7
8
# File 'app/presenters/task_presenter.rb', line 6

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

Instance Attribute Details

#tasksObject (readonly)

Returns the value of attribute tasks.



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

def tasks
  @tasks
end

Instance Method Details

#as_json(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/presenters/task_presenter.rb', line 10

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

#task_to_json(task) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/presenters/task_presenter.rb', line 20

def task_to_json(task)
  ticket = task.ticket
  project = ticket.project
  { id: task.id,

    projectId: project.id,
    projectSlug: project.slug,
    projectTitle: project.name,
    projectColor: project.color,

    ticketSystem: project.ticket_tracker_name,
    ticketUrl: ticket.ticket_tracker_ticket_url,
    ticketNumber: ticket.number,
    ticketType: ticket.type.to_s.downcase.dasherize,
    ticketSequence: ticket.extended_attributes["sequence"],  # <-- embeds knowledge of Houston::Scheduler

    shorthand: task.shorthand,
    description: task.description,
    effort: task.effort,
    firstReleaseAt: task.first_release_at,
    firstCommitAt: task.first_commit_at,
    completedAt: task.completed_at }
end