Class: Decidim::CollaborativeTexts::Document
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::CollaborativeTexts::Document
- Includes:
- Decidim::Coauthorable, HasComponent, Loggable, Publicable, Resourceable, Searchable, SoftDeletable, Traceable
- Defined in:
- app/models/decidim/collaborative_texts/document.rb
Overview
The data store for a document in the Decidim::CollaborativeTexts component. It stores a title, description and any other useful information to render a custom document.
Class Method Summary collapse
Instance Method Summary collapse
- #consolidated_body ⇒ Object
- #consolidated_version ⇒ Object
-
#current_version ⇒ Object
Returns the current version of the document.
- #has_suggestions? ⇒ Boolean
-
#restore ⇒ Object
The paranoia gem (used in soft-delete) applies the removed status to the “document_versions” association but it does not recursively restore them by default.
- #suggestions_enabled? ⇒ Boolean
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
38 39 40 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 38 def self.log_presenter_class_for(_log) Decidim::CollaborativeTexts::AdminLog::DocumentPresenter end |
Instance Method Details
#consolidated_body ⇒ Object
51 52 53 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 51 def consolidated_body consolidated_version&.body end |
#consolidated_version ⇒ Object
47 48 49 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 47 def consolidated_version document_versions.consolidated.last end |
#current_version ⇒ Object
Returns the current version of the document. Currently, the last one
43 44 45 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 43 def current_version document_versions.last || document_versions.build end |
#has_suggestions? ⇒ Boolean
62 63 64 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 62 def has_suggestions? current_version.suggestions.any? end |
#restore ⇒ Object
The paranoia gem (used in soft-delete) applies the removed status to the “document_versions” association but it does not recursively restore them by default. This model needs to have the document_versions synchronized always
58 59 60 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 58 def restore super(recursive: true) end |
#suggestions_enabled? ⇒ Boolean
66 67 68 |
# File 'app/models/decidim/collaborative_texts/document.rb', line 66 def suggestions_enabled? published? && accepting_suggestions? && !draft? end |