Class: ProblemPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, CommitHelper
Defined in:
app/presenters/problem_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommitHelper

#format_commit, #format_sha, #format_with_tickets_linked, #link_to_commit, #link_to_commit_range, #link_to_commit_range_for_deploy, #link_to_err, #link_to_release_commit_range

Constructor Details

#initialize(project, problems) ⇒ ProblemPresenter

Returns a new instance of ProblemPresenter.



7
8
9
10
# File 'app/presenters/problem_presenter.rb', line 7

def initialize(project, problems)
  @project = project
  @problems = problems
end

Instance Attribute Details

#problemsObject (readonly)

Returns the value of attribute problems.



5
6
7
# File 'app/presenters/problem_presenter.rb', line 5

def problems
  @problems
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'app/presenters/problem_presenter.rb', line 5

def project
  @project
end

Instance Method Details

#as_json(*args) ⇒ Object



12
13
14
15
16
# File 'app/presenters/problem_presenter.rb', line 12

def as_json(*args)
  Houston.benchmark "[problem_presenter] Prepare JSON" do
    @problems.map(&method(:problem_to_json))
  end
end

#present_notice(time, sha, environment_name) ⇒ Object



34
35
36
37
38
39
40
# File 'app/presenters/problem_presenter.rb', line 34

def present_notice(time, sha, environment_name)
  { at: time,
    ago: distance_of_time_in_words(time, Time.now).gsub("about ", "") + " ago",
    commit: (format_sha(sha) unless sha.blank?),
    commitUrl: (project.repo.commit_url(sha) if project.repo.respond_to?(:commit_url)),
    release: present_release(sha, environment_name) }
end

#present_release(sha, environment_name) ⇒ Object



42
43
44
45
46
47
# File 'app/presenters/problem_presenter.rb', line 42

def present_release(sha, environment_name)
  release = @project.releases.where(["LOWER(environment_name) = ?", environment_name.downcase]).find_by_commit1(sha) if environment_name && !sha.blank?
  { url: "/projects/#{@project.slug}/environments/#{environment_name}/releases/#{release.id}",
    at: release.created_at.strftime("%b %d"),
    environment: environment_name.humanize } if release
end

#problem_to_json(problem) ⇒ Object



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

def problem_to_json(problem)
  { id: problem.id,
    ticketId: problem.ticket.try(:id),
    ticketUrl: (@project.ticket_tracker.ticket_url(problem.ticket) if problem.ticket),
    ticketNumber: problem.ticket.try(:number),
    token: problem.err_ids.first,
    url: problem.url,
    message: problem.message,
    where: problem.where,
    noticesCount: problem.notices_count,
    comments: problem.comments,

    firstNotice: present_notice(problem.first_notice_at, problem.first_notice_commit, problem.first_notice_environment),
    lastNotice:  present_notice( problem.last_notice_at,  problem.last_notice_commit,  problem.last_notice_environment) }
end