Class: Pageflow::Revision
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Pageflow::Revision
- Includes:
- SerializedConfiguration, ThemeReferencer
- Defined in:
- app/models/pageflow/revision.rb
Overview
rubocop:todo Style/Documentation
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
- #entry_for_auto_generated_perma_id ⇒ 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
206 207 208 |
# File 'app/models/pageflow/revision.rb', line 206 def self.depublish_all published.update_all(published_until: Time.now) end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
222 223 224 |
# File 'app/models/pageflow/revision.rb', line 222 def self.ransackable_attributes(_auth_object = nil) %w[published_at] end |
Instance Method Details
#active_share_providers ⇒ Object
130 131 132 |
# File 'app/models/pageflow/revision.rb', line 130 def active_share_providers share_providers.select { |_k, v| v }.keys end |
#author ⇒ Object
118 119 120 |
# File 'app/models/pageflow/revision.rb', line 118 def read_attribute(:author) || Pageflow.config. end |
#chapters ⇒ Object
146 147 148 |
# File 'app/models/pageflow/revision.rb', line 146 def chapters super.tap { |c| c.first.is_first = true if c.present? } end |
#configuration ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'app/models/pageflow/revision.rb', line 210 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
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'app/models/pageflow/revision.rb', line 174 def copy revision = dup yield(revision) if block_given? .each do || .copy_to(revision) end revision.save! NestedRevisionComponentCopy.new( from: self, to: revision ).perform_for( revision_components: Pageflow.config.revision_components.to_a + [FileFolder, FileUsage] ) revision end |
#created_with ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/models/pageflow/revision.rb', line 159 def created_with if published_at :publish elsif snapshot_type == 'auto' :auto elsif snapshot_type == 'user' :user else :restore end end |
#creator ⇒ Object
134 135 136 |
# File 'app/models/pageflow/revision.rb', line 134 def creator super || NullUser.new end |
#entry_for_auto_generated_perma_id ⇒ Object
202 203 204 |
# File 'app/models/pageflow/revision.rb', line 202 def entry_for_auto_generated_perma_id entry end |
#find_file(model, id) ⇒ Object
102 103 104 105 |
# File 'app/models/pageflow/revision.rb', line 102 def find_file(model, id) file = files(model).find(id) UsedFile.new(file) end |
#find_file_by_perma_id(model, perma_id) ⇒ Object
107 108 109 110 111 112 |
# File 'app/models/pageflow/revision.rb', line 107 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
96 97 98 99 100 |
# File 'app/models/pageflow/revision.rb', line 96 def find_files(model) files(model).map do |file| UsedFile.new(file) end end |
#find_revision_components ⇒ Object
196 197 198 199 200 |
# File 'app/models/pageflow/revision.rb', line 196 def find_revision_components Pageflow.config.revision_components.flat_map do |model| model.all_for_revision(self).to_a end end |
#frozen? ⇒ Boolean
155 156 157 |
# File 'app/models/pageflow/revision.rb', line 155 def frozen? frozen_at.present? end |
#keywords ⇒ Object
126 127 128 |
# File 'app/models/pageflow/revision.rb', line 126 def keywords read_attribute(:keywords) || Pageflow.config. end |
#locale ⇒ Object
138 139 140 |
# File 'app/models/pageflow/revision.rb', line 138 def locale super.presence || I18n.default_locale.to_s end |
#main_storyline_chapters ⇒ Object
91 92 93 94 |
# File 'app/models/pageflow/revision.rb', line 91 def main_storyline_chapters main_storyline = storylines.first main_storyline ? main_storyline.chapters : Chapter.none end |
#pages ⇒ Object
142 143 144 |
# File 'app/models/pageflow/revision.rb', line 142 def pages super.tap { |p| p.first.is_first = true if p.present? } end |
#published? ⇒ Boolean
150 151 152 153 |
# File 'app/models/pageflow/revision.rb', line 150 def published? published_at.present? && Time.now >= published_at && (published_until.blank? || Time.now < published_until) end |
#publisher ⇒ Object
122 123 124 |
# File 'app/models/pageflow/revision.rb', line 122 def publisher read_attribute(:publisher) || Pageflow.config. end |
#share_providers ⇒ Object
114 115 116 |
# File 'app/models/pageflow/revision.rb', line 114 def share_providers self[:share_providers] || entry.entry_template.default_share_providers end |