Class: Pageflow::DraftEntry
Overview
A merged view of an entry and its draft revision
Defined Under Namespace
Classes: InvalidForeignKeyCustomAttributeError
Instance Attribute Summary
#entry, #revision
Class Method Summary
collapse
Instance Method Summary
collapse
#emphasize_chapter_beginning, #emphasize_new_pages, #home_button, #legal_info, #manual_start, #overview_button, #resolve_widgets, #theme, wrap_all_drafts
Constructor Details
#initialize(entry, draft = nil) ⇒ DraftEntry
Returns a new instance of DraftEntry.
8
9
10
|
# File 'app/models/pageflow/draft_entry.rb', line 8
def initialize(entry, draft = nil)
super(entry, draft || entry.draft)
end
|
Class Method Details
.accessible_by(ability, action) ⇒ Object
92
93
94
95
96
|
# File 'app/models/pageflow/draft_entry.rb', line 92
def self.accessible_by(ability, action)
Entry.includes(:draft).accessible_by(ability, action).map do |entry|
DraftEntry.new(entry)
end
end
|
.find(id) ⇒ Object
84
85
86
|
# File 'app/models/pageflow/draft_entry.rb', line 84
def self.find(id)
new(Entry.find(id))
end
|
.for_file_usage(usage) ⇒ Object
88
89
90
|
# File 'app/models/pageflow/draft_entry.rb', line 88
def self.for_file_usage(usage)
new(usage.revision.entry)
end
|
Instance Method Details
#create_file!(file_type, attributes) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/models/pageflow/draft_entry.rb', line 31
def create_file!(file_type, attributes)
check_foreign_key_custom_attributes(file_type.custom_attributes, attributes)
file_attributes = attributes.except(:configuration, :display_name, :folder_perma_id)
if file_name_attribute?(file_type)
file_attributes[:file_name] = generate_file_name(attributes[:display_name])
end
file = file_type.model.create!(file_attributes) { |f| f.entry = entry }
usage = revision.file_usages.create!(file:,
configuration: attributes[:configuration],
display_name: attributes[:display_name],
folder_perma_id: attributes[:folder_perma_id])
UsedFile.new(file, usage)
end
|
#create_folder!(attributes) ⇒ Object
65
66
67
|
# File 'app/models/pageflow/draft_entry.rb', line 65
def create_folder!(attributes)
draft.file_folders.create!(attributes)
end
|
#cutoff_mode_enabled_for?(_request) ⇒ Boolean
27
28
29
|
# File 'app/models/pageflow/draft_entry.rb', line 27
def cutoff_mode_enabled_for?(_request)
false
end
|
#entry_title ⇒ Object
So we can always get to the original Entry title.
15
16
17
|
# File 'app/models/pageflow/draft_entry.rb', line 15
def entry_title
entry.title
end
|
#published_revision? ⇒ Boolean
106
107
108
|
# File 'app/models/pageflow/draft_entry.rb', line 106
def published_revision?
false
end
|
#remove_file(file) ⇒ Object
rubocop:todo Metrics/AbcSize
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/models/pageflow/draft_entry.rb', line 49
def remove_file(file)
draft.file_usages.where(file:).destroy_all
file.file_type.nested_file_types.each do |nested_file_type|
nested_file_ids = file.nested_files(nested_file_type.model).map(&:id)
draft
.file_usages
.where(file_type: nested_file_type.model.name,
file_id: nested_file_ids)
.destroy_all
end
file.destroy if file.usages.reload.empty?
end
|
#save! ⇒ Object
76
77
78
|
# File 'app/models/pageflow/draft_entry.rb', line 76
def save!
draft.save!
end
|
#stylesheet_cache_key ⇒ Object
102
103
104
|
# File 'app/models/pageflow/draft_entry.rb', line 102
def stylesheet_cache_key
draft.cache_key
end
|
#stylesheet_model ⇒ Object
98
99
100
|
# File 'app/models/pageflow/draft_entry.rb', line 98
def stylesheet_model
draft
end
|
#translations(scope = -> { self }) ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/models/pageflow/draft_entry.rb', line 19
def translations(scope = -> { self }, **)
return [] unless entry.translation_group
PublishedEntry.wrap_all_drafts(
entry.translation_group.entries.instance_exec(&scope)
)
end
|
80
81
82
|
# File 'app/models/pageflow/draft_entry.rb', line 80
def update_meta_data!(attributes)
draft.update!(attributes)
end
|
#use_file(file, folder_perma_id: nil) ⇒ Object
69
70
71
72
73
74
|
# File 'app/models/pageflow/draft_entry.rb', line 69
def use_file(file, folder_perma_id: nil)
draft.file_usages.create!(file: file.to_model,
configuration: file.configuration,
display_name: file.display_name,
folder_perma_id:)
end
|