Class: Docsmith::DocumentVersion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Docsmith::DocumentVersion
- Defined in:
- lib/docsmith/document_version.rb
Overview
Immutable content snapshot. Table is docsmith_versions. Class name is DocumentVersion (not Version) to avoid colliding with lib/docsmith/version.rb which holds the Docsmith::VERSION constant.
Instance Method Summary collapse
-
#export(**options) ⇒ Hash
The JSON export envelope as a Hash, for embedding in a larger API response without a JSON round-trip.
- #previous_version ⇒ Docsmith::DocumentVersion?
-
#render(format, **options) ⇒ String
Renders this version's content in the given output format.
Instance Method Details
#export(**options) ⇒ Hash
The JSON export envelope as a Hash, for embedding in a larger API response without a JSON round-trip. Same shape as render(:json).
Note this is deliberately NOT as_json. DocumentVersion is an
ActiveRecord::Base, and overriding as_json would silently change what
render json: @version returns for every app already relying on standard
attribute serialization.
61 62 63 |
# File 'lib/docsmith/document_version.rb', line 61 def export(**) Rendering::JsonRenderer.new.to_h(self, **) end |
#previous_version ⇒ Docsmith::DocumentVersion?
30 31 32 33 34 |
# File 'lib/docsmith/document_version.rb', line 30 def previous_version document.document_versions .where("version_number < ?", version_number) .last end |
#render(format, **options) ⇒ String
Renders this version's content in the given output format.
42 43 44 45 46 47 48 |
# File 'lib/docsmith/document_version.rb', line 42 def render(format, **) case format.to_sym when :html then Rendering::HtmlRenderer.new.render(self, **) when :json then Rendering::JsonRenderer.new.render(self, **) else raise ArgumentError, "Unknown render format: #{format}. Supported: :html, :json" end end |