Sha256: 3722de972e74956f591d2dc7798b83156a7ea380c3735126bb982cea8033d362

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

class TicketPresenter
  include UrlHelper

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

  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

  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

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre app/presenters/ticket_presenter.rb
houston-core-0.7.0 app/presenters/ticket_presenter.rb
houston-core-0.7.0.beta4 app/presenters/ticket_presenter.rb
houston-core-0.7.0.beta3 app/presenters/ticket_presenter.rb
houston-core-0.7.0.beta2 app/presenters/ticket_presenter.rb
houston-core-0.7.0.beta app/presenters/ticket_presenter.rb
houston-core-0.6.3 app/presenters/ticket_presenter.rb
houston-core-0.6.2 app/presenters/ticket_presenter.rb
houston-core-0.6.1 app/presenters/ticket_presenter.rb
houston-core-0.6.0 app/presenters/ticket_presenter.rb
houston-core-0.5.6 app/presenters/ticket_presenter.rb
houston-core-0.5.5 app/presenters/ticket_presenter.rb
houston-core-0.5.4 app/presenters/ticket_presenter.rb
houston-core-0.5.3 app/presenters/ticket_presenter.rb
houston-core-0.5.2 app/presenters/ticket_presenter.rb
houston-core-0.5.1 app/presenters/ticket_presenter.rb
houston-core-0.5.0 app/presenters/ticket_presenter.rb