Class: Jiralicious::Issue::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/jiralicious/issue/comment.rb

Overview

The Comment class retrieves and controls the functionality of Comments associated with an Issue.

Instance Attribute Summary collapse

Attributes inherited from Base

#loaded

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all, #endpoint_name, endpoint_name, fetch, find, find_all, handler, issueKey_test, #loaded?, #method_missing, #numeric?, parent_name, #parent_name, #properties_from_hash, #reload

Methods included from Parsers::FieldParser

#parse!

Constructor Details

#initialize(decoded_json = nil) ⇒ Comment

Initialization Method

Arguments

:decoded_json (optional) rubyized json object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jiralicious/issue/comment.rb', line 18

def initialize(decoded_json = nil)
  if (decoded_json != nil)
    properties_from_hash(decoded_json)
    super(decoded_json)
    parse!(decoded_json)
    if self.respond_to?("comments")
      if self.comments.is_a? Array
        a = {}
        self.comments.each do |comment|
          a["_#{comment['id']}"] = Comment.new(comment)
        end
        self.comments = a
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jiralicious::Base

Instance Attribute Details

#jira_keyObject

Related Issue Key



10
11
12
# File 'lib/jiralicious/issue/comment.rb', line 10

def jira_key
  @jira_key
end

Class Method Details

.add(comment, key) ⇒ Object

Adds a new Comment to the Issue

Arguments

:comment (required) comment to post

:key (required) issue key



74
75
76
77
# File 'lib/jiralicious/issue/comment.rb', line 74

def add(comment, key)
  issueKey_test(key)
  fetch({:method => :post, :body => comment, :parent => parent_name, :parent_key => key})
end

.edit(comment, key, id) ⇒ Object

Updates a Comment based on Issue Key and Comment ID

Arguments

:comment (required) comment to post

:key (required) issue key

:id (required) comment id



89
90
91
92
# File 'lib/jiralicious/issue/comment.rb', line 89

def edit(comment, key, id)
  issueKey_test(key)
  fetch({:method => :put, :key => id, :body => comment, :parent => parent_name, :parent_key => key})
end

.find_by_key(key) ⇒ Object

Retrieves the Comments based on the Issue Key

Arguments

:key (required) issue key



42
43
44
45
46
47
48
# File 'lib/jiralicious/issue/comment.rb', line 42

def find_by_key(key)
  issueKey_test(key)
  response = fetch({:parent => parent_name, :parent_key => key})
  a = new(response)
  a.jira_key = key
  return a
end

.find_by_key_and_id(key, id) ⇒ Object

Retrieves the Comment based on the Issue Key and Comment ID

Arguments

:key (required) issue key

:id (required) comment id



58
59
60
61
62
63
64
# File 'lib/jiralicious/issue/comment.rb', line 58

def find_by_key_and_id(key, id)
  issueKey_test(key)
  response = fetch({:parent => parent_name, :parent_key => key, :key => id})
  a = new(response)
  a.jira_key = key
  return a
end

.remove(key, id) ⇒ Object

Removes/Deletes the Comment from the Jira Issue. It is not recommended to delete comments however the functionality is provided. It is recommended to override this function to throw an error or warning to maintain data integrity in systems that do not allow deleting from a remote location.

Arguments

:key (required) issue key

:id (required) comment id



106
107
108
109
# File 'lib/jiralicious/issue/comment.rb', line 106

def remove(key, id)
  issueKey_test(key)
  fetch({:method => :delete, :body_to_params => true, :key => id, :parent => parent_name, :parent_key => key})
end

Instance Method Details

#add(comment) ⇒ Object

Adds a new Comment to the loaded Issue

Arguments

:comment (required) comment text



128
129
130
# File 'lib/jiralicious/issue/comment.rb', line 128

def add(comment)
  self.class.add(comment, @jira_key)
end

#edit(comment) ⇒ Object

Updates a Comment based on loaded Issue and Comment

Arguments

:comment (required) comment text



138
139
140
# File 'lib/jiralicious/issue/comment.rb', line 138

def edit(comment)
  self.class.edit(comment, @jira_key, self.id)
end

#find_by_id(id) ⇒ Object

Retrieves the Comment based on the loaded Issue and Comment ID

Arguments

:id (required) comment id



118
119
120
# File 'lib/jiralicious/issue/comment.rb', line 118

def find_by_id(id)
  self.class.find_by_key_and_id(@jira_key, id)
end

#remove(id = self.id) ⇒ Object

Removes/Deletes the Comment from the Jira Issue. It is not recommended to delete comments. However, the functionality is provided. It is recommended to override this function to throw an error or warning to maintain data integrity in systems that do not allow deleting from a remote location.

Arguments

:id (optional) comment id



152
153
154
# File 'lib/jiralicious/issue/comment.rb', line 152

def remove(id = self.id)
  self.class.remove(@jira_key, id)
end