Class: ArticleVariants::SnapshotWriter
- Inherits:
-
Object
- Object
- ArticleVariants::SnapshotWriter
- Defined in:
- app/services/postnhost/publishing/article_variants/snapshot_writer.rb
Constant Summary collapse
- ATTRIBUTES =
i[ language_id title title_tag og_title schema_headline custom_excerpt auto_excerpt content ].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(variant:) ⇒ SnapshotWriter
constructor
A new instance of SnapshotWriter.
Constructor Details
#initialize(variant:) ⇒ SnapshotWriter
Returns a new instance of SnapshotWriter.
9 10 11 |
# File 'app/services/postnhost/publishing/article_variants/snapshot_writer.rb', line 9 def initialize(variant:) @variant = variant end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/postnhost/publishing/article_variants/snapshot_writer.rb', line 13 def call validate! version = variant.paper_trail.save_with_version raise Error, "could not capture the snapshot source version" unless version&.persisted? snapshot = variant.article_variant_snapshot || variant.build_article_variant_snapshot snapshot.assign_attributes( variant.attributes.symbolize_keys.slice(*ATTRIBUTES).merge( article_id: variant.article_id, paper_trail_version: version ) ) snapshot.published_at ||= Time.current snapshot.save! snapshot end |