Class: PageVersion

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Trek::Sectionable
Defined in:
lib/generators/trek/templates/models/page_version.rb

Overview

‘PageVersion` is a version of a `Page`. There’s always only one ‘current` version per page, and there can be other versions. Any version can be promoted to `current`.

Constant Summary

Constants included from Trek::Sectionable

Trek::Sectionable::SECTIONS, Trek::Sectionable::SECTION_NAMES

Instance Method Summary collapse

Instance Method Details

#current?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/generators/trek/templates/models/page_version.rb', line 25

def current?
  current_since?
end

#current_imageObject



29
30
31
# File 'lib/generators/trek/templates/models/page_version.rb', line 29

def current_image
  image
end

#current_image_urlObject



33
34
35
# File 'lib/generators/trek/templates/models/page_version.rb', line 33

def current_image_url
  image_url
end

#other_versionsObject



37
38
39
# File 'lib/generators/trek/templates/models/page_version.rb', line 37

def other_versions
  page.versions.where.not(id:)
end

#set_default_nameObject



41
42
43
44
45
# File 'lib/generators/trek/templates/models/page_version.rb', line 41

def set_default_name
  return if page.blank?

  self.name ||= "#{page.title} (#{I18n.l(Time.zone.now.to_date)})"
end

#to_sObject



21
22
23
# File 'lib/generators/trek/templates/models/page_version.rb', line 21

def to_s
  name
end