Class: TicketMaster::Provider::Lighthouse::Comment
- Inherits:
-
Base::Comment
- Object
- Base::Comment
- TicketMaster::Provider::Lighthouse::Comment
- Defined in:
- lib/provider/comment.rb
Overview
The comment class for ticketmaster-lighthouse
Due to the way lighthouse handles tickets, comments aren’t really comments, but versions of the ticket.
-
author => user_name (read-only)
-
body => description
-
id => position in the versions array (set by the initializer)
-
created_at
-
updated_at
-
ticket_id => number (read-only)
-
project_id => (set by the initializer)
Constant Summary collapse
- API =
::Lighthouse::Ticket
Class Method Summary collapse
- .create(*options) ⇒ Object
-
.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object
A custom find_by_attributes.
-
.find_by_id(project_id, ticket_id, id) ⇒ Object
A custom find_by_id The “comment” id is it’s index in the versions array.
-
.index_of(versions, needle) ⇒ Object
The Array#index method doesn’t work for the versions…
-
.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object
A custom searcher.
Instance Method Summary collapse
-
#author ⇒ Object
The author’s name.
-
#initialize(ticket, id) ⇒ Comment
constructor
A new instance of Comment.
Constructor Details
#initialize(ticket, id) ⇒ Comment
Returns a new instance of Comment.
59 60 61 62 63 64 65 66 67 |
# File 'lib/provider/comment.rb', line 59 def initialize(ticket, id) @system_data ||= {} return super(ticket) unless ticket.respond_to?('versions') and ticket.versions.respond_to?('[]') @system_data[:ticket] = @system_data[:client] = ticket @system_data[:version] = ticket.versions[id] self.project_id = ticket.[:project_id] self.id = id super(@system_data[:version].attributes) end |
Class Method Details
.create(*options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/provider/comment.rb', line 45 def self.create(*) attributes = .first ticket_id = attributes.delete(:ticket_id) || attributes.delete('ticket_id') project_id = attributes.delete(:project_id) || attributes.delete('project_id') ticket = self::API.find(ticket_id, :params => {:project_id => project_id}) attributes.each do |k, v| ticket.send("#{k}=", v) end versions = ticket.attributes.delete('versions') ticket.save ticket.attributes['versions'] = versions self.find_by_id project_id, ticket_id, ticket.versions.length end |
.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object
A custom find_by_attributes
27 28 29 30 31 32 33 |
# File 'lib/provider/comment.rb', line 27 def self.find_by_attributes(project_id, ticket_id, attributes = {}) result = self.search(project_id, ticket_id, attributes) result[0].shift result[0].collect do |comment| self.new(result[1], index_of(result[1].versions, comment)) if !comment.body.blank? end.compact end |
.find_by_id(project_id, ticket_id, id) ⇒ Object
A custom find_by_id The “comment” id is it’s index in the versions array. An id of 0 therefore exists and should be the first ticket (original)
21 22 23 |
# File 'lib/provider/comment.rb', line 21 def self.find_by_id(project_id, ticket_id, id) self.new API.find(ticket_id, :params => {:project_id => project_id}), id end |
.index_of(versions, needle) ⇒ Object
The Array#index method doesn’t work for the versions… because it seems they’re all equal.
37 38 39 40 41 42 43 |
# File 'lib/provider/comment.rb', line 37 def self.index_of(versions, needle) result = nil versions.each_with_index do |version, index| result = index if version.attributes == needle.attributes end result end |
.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object
A custom searcher
It returns a custom result because we need the original ticket to make a comment.
72 73 74 75 76 |
# File 'lib/provider/comment.rb', line 72 def self.search(project_id, ticket_id, = {}, limit = 1000) ticket = API.find(ticket_id, :params => {:project_id => project_id}) comments = ticket.versions [search_by_attribute(comments, , limit), ticket] end |
Instance Method Details
#author ⇒ Object
The author’s name
79 80 81 |
# File 'lib/provider/comment.rb', line 79 def user_name end |