Class: Docsmith::Document
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Docsmith::Document
- Defined in:
- lib/docsmith/document.rb
Overview
AR model backed by docsmith_documents. Serves as both a standalone versioned document and the shadow record auto-created when Docsmith::Versionable is included on any AR model.
Shadow record lifecycle:
include Docsmith::Versionable on Article → first save_version! call does:
Docsmith::Document.find_or_create_by!(subject: article_instance)
subject_type / subject_id link back to the originating record.
Class Method Summary collapse
-
.from_record(record, field: nil) ⇒ Docsmith::Document
Find or create the shadow Document for an existing AR record.
Instance Method Summary collapse
-
#current_version ⇒ Docsmith::DocumentVersion?
Latest version by version_number.
Class Method Details
.from_record(record, field: nil) ⇒ Docsmith::Document
Find or create the shadow Document for an existing AR record.
37 38 39 40 41 42 |
# File 'lib/docsmith/document.rb', line 37 def self.from_record(record, field: nil) find_or_create_by!(subject: record) do |doc| doc.content_type = "markdown" doc.title = record.respond_to?(:title) ? record.title.to_s : record.class.name end end |
Instance Method Details
#current_version ⇒ Docsmith::DocumentVersion?
Returns latest version by version_number.
29 30 31 |
# File 'lib/docsmith/document.rb', line 29 def current_version document_versions.last end |