Class: ActiveProject::Resources::Comment

Inherits:
PersistableResource show all
Defined in:
lib/active_project/resources/comment.rb

Overview

Represents a Comment on an Issue

Instance Attribute Summary

Attributes inherited from BaseResource

#adapter, #attributes, #raw_data

Instance Method Summary collapse

Methods inherited from PersistableResource

#persisted?

Methods inherited from BaseResource

def_members, #initialize, #inspect, members, #method_missing, #respond_to_missing?, #to_h

Constructor Details

This class inherits a constructor from ActiveProject::Resources::BaseResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveProject::Resources::BaseResource

Instance Method Details

#deleteObject Also known as: destroy

Remove comment remotely and freeze this instance.



28
29
30
31
32
33
34
# File 'lib/active_project/resources/comment.rb', line 28

def delete
  raise "id missing – not persisted" if id.nil?

  @adapter.delete_comment(id, adapter_context)
  freeze
  true
end

#saveObject

For new comments (no id) call add_comment; otherwise update.



11
12
13
14
15
16
17
18
19
# File 'lib/active_project/resources/comment.rb', line 11

def save
  fresh = if id.nil?
            @adapter.add_comment(issue_id, body, adapter_context)
  else
            @adapter.update_comment(id, body, adapter_context)
  end
  copy_from(fresh)
  true
end

#update(attrs = {}) ⇒ Object

Shorthand that mutates body and persists.



22
23
24
25
# File 'lib/active_project/resources/comment.rb', line 22

def update(attrs = {})
  self.body = attrs[:body] if attrs[:body]
  save
end