Class: ContentBlockVersion

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/content_block_version.rb

Constant Summary collapse

EVENTS =
%w[create update rollback publish unpublish visual_editor].freeze

Instance Method Summary collapse

Instance Method Details

#diff_from(other) ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/models/content_block_version.rb', line 17

def diff_from(other)
  fields = %i[title content rich_content_html content_type published]
  fields.each_with_object({}) do |field, changes|
    old_val = other&.public_send(field)
    new_val = public_send(field)
    changes[field] = { old: old_val, new: new_val } if old_val != new_val
  end
end

#previousObject



26
27
28
29
# File 'app/models/content_block_version.rb', line 26

def previous
  content_block.versions.where(version_number: ...version_number)
               .order(version_number: :desc).first
end

#snapshotObject



31
32
33
# File 'app/models/content_block_version.rb', line 31

def snapshot
  { title:, content:, rich_content_html:, content_type:, published: }
end