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
202 203 204 |
# File 'app/models/pageflow/revision.rb', line 202 def self.depublish_all published.update_all(published_until: Time.now) end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
218 219 220 |
# File 'app/models/pageflow/revision.rb', line 218 def self.ransackable_attributes(_auth_object = nil) %w[published_at] end |
Instance Method Details
#active_share_providers ⇒ Object
127 128 129 |
# File 'app/models/pageflow/revision.rb', line 127 def active_share_providers share_providers.select { |_k, v| v }.keys end |
#author ⇒ Object
115 116 117 |
# File 'app/models/pageflow/revision.rb', line 115 def read_attribute(:author) || Pageflow.config. end |
#chapters ⇒ Object
143 144 145 |
# File 'app/models/pageflow/revision.rb', line 143 def chapters super.tap { |c| c.first.is_first = true if c.present? } end |
#configuration ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'app/models/pageflow/revision.rb', line 206 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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'app/models/pageflow/revision.rb', line 171 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 + [FileUsage] ) revision end |
#created_with ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/models/pageflow/revision.rb', line 156 def created_with if published_at :publish elsif snapshot_type == 'auto' :auto elsif snapshot_type == 'user' :user else :restore end end |
#creator ⇒ Object
131 132 133 |
# File 'app/models/pageflow/revision.rb', line 131 def creator super || NullUser.new end |
#entry_for_auto_generated_perma_id ⇒ Object
198 199 200 |
# File 'app/models/pageflow/revision.rb', line 198 def entry_for_auto_generated_perma_id entry end |
#find_file(model, id) ⇒ Object
99 100 101 102 |
# File 'app/models/pageflow/revision.rb', line 99 def find_file(model, id) file = files(model).find(id) UsedFile.new(file) end |
#find_file_by_perma_id(model, perma_id) ⇒ Object
104 105 106 107 108 109 |
# File 'app/models/pageflow/revision.rb', line 104 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
93 94 95 96 97 |
# File 'app/models/pageflow/revision.rb', line 93 def find_files(model) files(model).map do |file| UsedFile.new(file) end end |
#find_revision_components ⇒ Object
192 193 194 195 196 |
# File 'app/models/pageflow/revision.rb', line 192 def find_revision_components Pageflow.config.revision_components.flat_map do |model| model.all_for_revision(self).to_a end end |
#frozen? ⇒ Boolean
152 153 154 |
# File 'app/models/pageflow/revision.rb', line 152 def frozen? frozen_at.present? end |
#keywords ⇒ Object
123 124 125 |
# File 'app/models/pageflow/revision.rb', line 123 def keywords read_attribute(:keywords) || Pageflow.config. end |
#locale ⇒ Object
135 136 137 |
# File 'app/models/pageflow/revision.rb', line 135 def locale super.presence || I18n.default_locale.to_s end |
#main_storyline_chapters ⇒ Object
88 89 90 91 |
# File 'app/models/pageflow/revision.rb', line 88 def main_storyline_chapters main_storyline = storylines.first main_storyline ? main_storyline.chapters : Chapter.none end |
#pages ⇒ Object
139 140 141 |
# File 'app/models/pageflow/revision.rb', line 139 def pages super.tap { |p| p.first.is_first = true if p.present? } end |
#published? ⇒ Boolean
147 148 149 150 |
# File 'app/models/pageflow/revision.rb', line 147 def published? published_at.present? && Time.now >= published_at && (published_until.blank? || Time.now < published_until) end |
#publisher ⇒ Object
119 120 121 |
# File 'app/models/pageflow/revision.rb', line 119 def publisher read_attribute(:publisher) || Pageflow.config. end |
#share_providers ⇒ Object
111 112 113 |
# File 'app/models/pageflow/revision.rb', line 111 def share_providers self[:share_providers] || entry.entry_template.default_share_providers end |