Class: TicketMaster::Provider::Pivotal::Comment

Inherits:
Base::Comment
  • Object
show all
Defined in:
lib/provider/comment.rb

Overview

The comment class for ticketmaster-pivotal

  • author

  • body => text

  • id => position in the versions array (set by the initializer)

  • created_at => noted_at

  • updated_at => noted_at

  • ticket_id (actually the story id)

  • project_id

Constant Summary collapse

API =
PivotalAPI::Note

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id, ticket_id, *object) ⇒ Comment

Returns a new instance of Comment.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/provider/comment.rb', line 47

def initialize(project_id, ticket_id, *object)
  if object.first
    object = object.first
    unless object.is_a? Hash
      hash = {:id => object.id,
              :body => object.text,
              :update_at => object.noted_at,
              :created_at => object.noted_at,
              :project_id => project_id,
              :ticket_id => ticket_id
              }
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.create(project_id, ticket_id, *options) ⇒ Object

A custom creator We didn’t really need to do much other than change the :ticket_id attribute to :story_id



37
38
39
40
41
42
43
44
45
# File 'lib/provider/comment.rb', line 37

def self.create(project_id, ticket_id, *options)
  first = options.first
  first[:story_id] ||= ticket_id
  first[:project_id] ||= project_id
  first[:text] ||= first.delete(:body) || first.delete('body')
  note = PivotalAPI::Note.new(first)
  note.save
  self.new(project_id, ticket_id, note)
end

.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object

A custom find_by_attributes



23
24
25
# File 'lib/provider/comment.rb', line 23

def self.find_by_attributes(project_id, ticket_id, attributes = {})
  self.search(project_id, ticket_id, attributes).collect { |comment| self.new(project_id, ticket_id, comment) }
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)



17
18
19
# File 'lib/provider/comment.rb', line 17

def self.find_by_id(project_id, ticket_id, id)
  self.new(project_id, ticket_id, PivotalAPI::Note.find(id, :params => {:project_id => project_id, :story_id => ticket_id}))
end

.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object

A custom searcher

It returns a custom result because we need the original story to make a comment.



30
31
32
33
# File 'lib/provider/comment.rb', line 30

def self.search(project_id, ticket_id, options = {}, limit = 1000)
  comments = PivotalAPI::Note.find(:all, :params => {:project_id => project_id, :story_id => ticket_id})
  search_by_attribute(comments, options, limit)
end

Instance Method Details

#body=(bod) ⇒ Object



65
66
67
# File 'lib/provider/comment.rb', line 65

def body=(bod)
  self.text = bod
end