Class: Plum::Entry
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Plum::Entry
- Includes:
- SiteScoped
- Defined in:
- app/models/plum/entry.rb
Constant Summary collapse
- HOMEPAGE_SLUG =
The page served at "/" — Plum resolves the homepage by this slug (convention over configuration). Its slug is locked and it can't be deleted while published, so a non-technical editor can't orphan the home page by renaming or removing it.
"home".freeze
Instance Method Summary collapse
- #field_value(handle) ⇒ Object
- #homepage? ⇒ Boolean
- #record_revision!(editor: nil) ⇒ Object
- #restore_revision!(revision, editor: nil) ⇒ Object
- #translation_group ⇒ Object
Instance Method Details
#field_value(handle) ⇒ Object
44 45 46 |
# File 'app/models/plum/entry.rb', line 44 def field_value(handle) data&.dig(handle) end |
#homepage? ⇒ Boolean
48 49 50 |
# File 'app/models/plum/entry.rb', line 48 def homepage? slug == HOMEPAGE_SLUG end |
#record_revision!(editor: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/plum/entry.rb', line 52 def record_revision!(editor: nil) identity = revision_editor_identity(editor) attributes = { site: site, editor_name: identity[:name], editor_email: identity[:email], editor_gid: identity[:gid], snapshot: { "title" => title, "slug" => slug, "status" => status, "published_at" => published_at&.iso8601, "data" => data.to_h.deep_dup, "term_ids" => term_ids } } attributes[:editor] = editor if editor.is_a?(Plum::User) revisions.create!(attributes) end |
#restore_revision!(revision, editor: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/plum/entry.rb', line 72 def restore_revision!(revision, editor: nil) raise ArgumentError, "Revision does not belong to this entry" unless revision.entry_id == id && revision.site_id == site_id snapshot = revision.snapshot.to_h transaction do update!(snapshot.slice("title", "slug", "status", "published_at", "data")) self.term_ids = site.terms.where(id: Array(snapshot["term_ids"])).pluck(:id) record_revision!(editor: editor) end end |
#translation_group ⇒ Object
83 84 85 86 |
# File 'app/models/plum/entry.rb', line 83 def translation_group source = origin || self [ source, *source.translations ].uniq.sort_by(&:locale) end |