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
191 192 193 |
# File 'app/models/pageflow/revision.rb', line 191 def self.depublish_all published.update_all(:published_until => Time.now) end |
Instance Method Details
#active_share_providers ⇒ Object
120 121 122 |
# File 'app/models/pageflow/revision.rb', line 120 def active_share_providers share_providers.select { |_k, v| v }.keys end |
#author ⇒ Object
108 109 110 |
# File 'app/models/pageflow/revision.rb', line 108 def read_attribute(:author) || Pageflow.config. end |
#chapters ⇒ Object
136 137 138 |
# File 'app/models/pageflow/revision.rb', line 136 def chapters super.tap { |c| c.first.is_first = true if c.present? } end |
#configuration ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'app/models/pageflow/revision.rb', line 195 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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/models/pageflow/revision.rb', line 164 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
149 150 151 152 153 154 155 156 157 158 159 |
# File 'app/models/pageflow/revision.rb', line 149 def created_with if published_at :publish elsif snapshot_type == 'auto' :auto elsif snapshot_type == 'user' :user else :restore end end |
#creator ⇒ Object
124 125 126 |
# File 'app/models/pageflow/revision.rb', line 124 def creator super || NullUser.new end |
#find_file(model, id) ⇒ Object
93 94 95 96 |
# File 'app/models/pageflow/revision.rb', line 93 def find_file(model, id) file = files(model).find(id) UsedFile.new(file) end |
#find_file_by_perma_id(model, perma_id) ⇒ Object
98 99 100 101 102 |
# File 'app/models/pageflow/revision.rb', line 98 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
87 88 89 90 91 |
# File 'app/models/pageflow/revision.rb', line 87 def find_files(model) files(model).map do |file| UsedFile.new(file) end end |
#find_revision_components ⇒ Object
185 186 187 188 189 |
# File 'app/models/pageflow/revision.rb', line 185 def find_revision_components Pageflow.config.revision_components.flat_map do |model| model.all_for_revision(self).to_a end end |
#frozen? ⇒ Boolean
145 146 147 |
# File 'app/models/pageflow/revision.rb', line 145 def frozen? frozen_at.present? end |
#keywords ⇒ Object
116 117 118 |
# File 'app/models/pageflow/revision.rb', line 116 def keywords read_attribute(:keywords) || Pageflow.config. end |
#locale ⇒ Object
128 129 130 |
# File 'app/models/pageflow/revision.rb', line 128 def locale super.presence || I18n.default_locale.to_s end |
#main_storyline_chapters ⇒ Object
82 83 84 85 |
# File 'app/models/pageflow/revision.rb', line 82 def main_storyline_chapters main_storyline = storylines.first main_storyline ? main_storyline.chapters : Chapter.none end |
#pages ⇒ Object
132 133 134 |
# File 'app/models/pageflow/revision.rb', line 132 def pages super.tap { |p| p.first.is_first = true if p.present? } end |
#published? ⇒ Boolean
140 141 142 143 |
# File 'app/models/pageflow/revision.rb', line 140 def published? (published_at.present? && Time.now >= published_at) && (published_until.blank? || Time.now < published_until) end |
#publisher ⇒ Object
112 113 114 |
# File 'app/models/pageflow/revision.rb', line 112 def publisher read_attribute(:publisher) || Pageflow.config. end |
#share_providers ⇒ Object
104 105 106 |
# File 'app/models/pageflow/revision.rb', line 104 def share_providers self[:share_providers] || entry.entry_template.default_share_providers end |