Class: Docsmith::Comments::Manager
- Inherits:
-
Object
- Object
- Docsmith::Comments::Manager
- Defined in:
- lib/docsmith/comments/manager.rb
Overview
Service object for creating and resolving comments on document versions.
Class Method Summary collapse
-
.add!(document, version_number:, body:, author:, anchor: nil, parent: nil) ⇒ Comments::Comment
Adds a comment to a specific version of a document.
-
.resolve!(comment, by:) ⇒ Comments::Comment
Marks a comment as resolved.
Class Method Details
.add!(document, version_number:, body:, author:, anchor: nil, parent: nil) ⇒ Comments::Comment
Adds a comment to a specific version of a document.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/docsmith/comments/manager.rb', line 18 def add!(document, version_number:, body:, author:, anchor: nil, parent: nil) version = Docsmith::DocumentVersion.find_by!(document: document, version_number: version_number) anchor_type = anchor ? "range" : "document" anchor_data = if anchor Anchor.build(version.content.to_s, start_offset: anchor[:start_offset], end_offset: anchor[:end_offset]) else {} end comment = Comment.create!( version: version, author: , body: body, anchor_type: anchor_type, anchor_data: anchor_data, parent: parent, resolved: false ) Events::Notifier.instrument(:comment_added, record: document.subject || document, document: document, version: version, author: , comment: comment ) comment end |
.resolve!(comment, by:) ⇒ Comments::Comment
Marks a comment as resolved.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docsmith/comments/manager.rb', line 56 def resolve!(comment, by:) comment.update!(resolved: true, resolved_by: by, resolved_at: Time.current) document = comment.version.document Events::Notifier.instrument(:comment_resolved, record: document.subject || document, document: document, version: comment.version, author: by, comment: comment ) comment end |