Class: Pageflow::Revision
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Pageflow::Revision
- Includes:
- ThemeReferencer
- Defined in:
- app/models/pageflow/revision.rb
Constant Summary collapse
- PAGE_ORDER =
[ 'pageflow_storylines.position ASC', 'pageflow_chapters.position ASC', 'pageflow_pages.position ASC' ].join(',')
- CHAPTER_ORDER =
[ 'pageflow_storylines.position ASC', 'pageflow_chapters.position ASC' ].join(',')
Class Method Summary collapse
Instance Method Summary collapse
- #chapters ⇒ Object
- #copy {|revision| ... } ⇒ Object
- #created_with ⇒ Object
- #creator ⇒ Object
- #find_file(model, id) ⇒ Object
- #find_files(model) ⇒ Object
- #frozen? ⇒ Boolean
- #locale ⇒ Object
- #main_storyline_chapters ⇒ Object
- #pages ⇒ Object
- #published? ⇒ Boolean
Methods included from ThemeReferencer
Class Method Details
.depublish_all ⇒ Object
158 159 160 |
# File 'app/models/pageflow/revision.rb', line 158 def self.depublish_all published.update_all(:published_until => Time.now) end |
Instance Method Details
#chapters ⇒ Object
106 107 108 |
# File 'app/models/pageflow/revision.rb', line 106 def chapters super.tap { |c| c.first.is_first = true if c.present? } end |
#copy {|revision| ... } ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/models/pageflow/revision.rb', line 131 def copy(&block) revision = dup yield(revision) if block_given? .each do || .copy_to(revision) end storylines.each do |storyline| storyline.copy_to(revision) end file_usages.each do |file_usage| file_usage.copy_to(revision) end Pageflow.config.revision_components.each do |model| model.all_for_revision(self).each do |record| record.copy_to(revision) end end revision.save! revision end |
#created_with ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/models/pageflow/revision.rb', line 119 def created_with if published_at :publish elsif snapshot_type == 'auto' :auto elsif snapshot_type == 'user' :user else :restore end end |
#creator ⇒ Object
94 95 96 |
# File 'app/models/pageflow/revision.rb', line 94 def creator super || NullUser.new end |
#find_file(model, id) ⇒ Object
89 90 91 92 |
# File 'app/models/pageflow/revision.rb', line 89 def find_file(model, id) file = files(model).find(id) UsedFile.new(file) end |
#find_files(model) ⇒ Object
83 84 85 86 87 |
# File 'app/models/pageflow/revision.rb', line 83 def find_files(model) files(model).map do |file| UsedFile.new(file) end end |
#frozen? ⇒ Boolean
115 116 117 |
# File 'app/models/pageflow/revision.rb', line 115 def frozen? frozen_at.present? end |
#locale ⇒ Object
98 99 100 |
# File 'app/models/pageflow/revision.rb', line 98 def locale super.presence || I18n.default_locale end |
#main_storyline_chapters ⇒ Object
78 79 80 81 |
# File 'app/models/pageflow/revision.rb', line 78 def main_storyline_chapters main_storyline = storylines.first main_storyline ? main_storyline.chapters : Chapter.none end |
#pages ⇒ Object
102 103 104 |
# File 'app/models/pageflow/revision.rb', line 102 def pages super.tap { |p| p.first.is_first = true if p.present? } end |
#published? ⇒ Boolean
110 111 112 113 |
# File 'app/models/pageflow/revision.rb', line 110 def published? (published_at.present? && Time.now >= published_at) && (published_until.blank? || Time.now < published_until) end |