Class: Pageflow::Revision
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Pageflow::Revision
- Includes:
- SerializedConfiguration, 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
- #active_share_providers ⇒ Object
- #author ⇒ Object
- #chapters ⇒ Object
- #configuration ⇒ Object
-
#copy {|revision| ... } ⇒ Object
Public interface for copying a revision.
- #created_with ⇒ Object
- #creator ⇒ Object
- #find_file(model, id) ⇒ Object
- #find_file_by_perma_id(model, perma_id) ⇒ Object
- #find_files(model) ⇒ Object
- #find_revision_components ⇒ Object
- #frozen? ⇒ Boolean
- #keywords ⇒ Object
- #locale ⇒ Object
- #main_storyline_chapters ⇒ Object
- #pages ⇒ Object
- #published? ⇒ Boolean
- #publisher ⇒ Object
- #share_providers ⇒ Object
Methods included from ThemeReferencer
Class Method Details
.depublish_all ⇒ Object
193 194 195 |
# File 'app/models/pageflow/revision.rb', line 193 def self.depublish_all published.update_all(:published_until => Time.now) end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
209 210 211 |
# File 'app/models/pageflow/revision.rb', line 209 def self.ransackable_attributes(_auth_object = nil) %w[published_at] end |
Instance Method Details
#active_share_providers ⇒ Object
122 123 124 |
# File 'app/models/pageflow/revision.rb', line 122 def active_share_providers share_providers.select { |_k, v| v }.keys end |
#author ⇒ Object
110 111 112 |
# File 'app/models/pageflow/revision.rb', line 110 def read_attribute(:author) || Pageflow.config. end |
#chapters ⇒ Object
138 139 140 |
# File 'app/models/pageflow/revision.rb', line 138 def chapters super.tap { |c| c.first.is_first = true if c.present? } end |
#configuration ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/models/pageflow/revision.rb', line 197 def configuration { 'emphasize_chapter_beginning' => emphasize_chapter_beginning, 'emphasize_new_pages' => emphasize_new_pages, 'home_url' => home_url, 'home_button_enabled' => , 'manual_start' => manual_start, 'overview_button_enabled' => }.delete_if { |_k, v| v.nil? } .merge(read_attribute(:configuration) || {}) end |
#copy {|revision| ... } ⇒ Object
Public interface for copying a revision
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/models/pageflow/revision.rb', line 166 def copy(&block) revision = dup yield(revision) if block_given? .each do || .copy_to(revision) end file_usages.each do |file_usage| file_usage.copy_to(revision) end find_revision_components.each do |revision_component| revision_component.copy_to(revision) end revision.save! revision end |
#created_with ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/pageflow/revision.rb', line 151 def created_with if published_at :publish elsif snapshot_type == 'auto' :auto elsif snapshot_type == 'user' :user else :restore end end |
#creator ⇒ Object
126 127 128 |
# File 'app/models/pageflow/revision.rb', line 126 def creator super || NullUser.new end |
#find_file(model, id) ⇒ Object
95 96 97 98 |
# File 'app/models/pageflow/revision.rb', line 95 def find_file(model, id) file = files(model).find(id) UsedFile.new(file) end |
#find_file_by_perma_id(model, perma_id) ⇒ Object
100 101 102 103 104 |
# File 'app/models/pageflow/revision.rb', line 100 def find_file_by_perma_id(model, perma_id) file = files(model).find_by(pageflow_file_usages: {file_perma_id: perma_id}) return unless file UsedFile.new(file) end |
#find_files(model) ⇒ Object
89 90 91 92 93 |
# File 'app/models/pageflow/revision.rb', line 89 def find_files(model) files(model).map do |file| UsedFile.new(file) end end |
#find_revision_components ⇒ Object
187 188 189 190 191 |
# File 'app/models/pageflow/revision.rb', line 187 def find_revision_components Pageflow.config.revision_components.flat_map do |model| model.all_for_revision(self).to_a end end |
#frozen? ⇒ Boolean
147 148 149 |
# File 'app/models/pageflow/revision.rb', line 147 def frozen? frozen_at.present? end |
#keywords ⇒ Object
118 119 120 |
# File 'app/models/pageflow/revision.rb', line 118 def keywords read_attribute(:keywords) || Pageflow.config. end |
#locale ⇒ Object
130 131 132 |
# File 'app/models/pageflow/revision.rb', line 130 def locale super.presence || I18n.default_locale.to_s end |
#main_storyline_chapters ⇒ Object
84 85 86 87 |
# File 'app/models/pageflow/revision.rb', line 84 def main_storyline_chapters main_storyline = storylines.first main_storyline ? main_storyline.chapters : Chapter.none end |
#pages ⇒ Object
134 135 136 |
# File 'app/models/pageflow/revision.rb', line 134 def pages super.tap { |p| p.first.is_first = true if p.present? } end |
#published? ⇒ Boolean
142 143 144 145 |
# File 'app/models/pageflow/revision.rb', line 142 def published? (published_at.present? && Time.now >= published_at) && (published_until.blank? || Time.now < published_until) end |
#publisher ⇒ Object
114 115 116 |
# File 'app/models/pageflow/revision.rb', line 114 def publisher read_attribute(:publisher) || Pageflow.config. end |
#share_providers ⇒ Object
106 107 108 |
# File 'app/models/pageflow/revision.rb', line 106 def share_providers self[:share_providers] || entry.entry_template.default_share_providers end |