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, #manual_start, #overview_button, #resolve_widgets, #theme
Constructor Details
#initialize(entry, draft = nil) ⇒ DraftEntry
Returns a new instance of DraftEntry.
6
7
8
|
# File 'app/models/pageflow/draft_entry.rb', line 6
def initialize(entry, draft = nil)
super(entry, draft || entry.draft)
end
|
Class Method Details
.accessible_by(ability, action) ⇒ Object
66
67
68
69
70
|
# File 'app/models/pageflow/draft_entry.rb', line 66
def self.accessible_by(ability, action)
Entry.includes(:draft).accessible_by(ability, action).map do |entry|
DraftEntry.new(entry)
end
end
|
.find(id) ⇒ Object
58
59
60
|
# File 'app/models/pageflow/draft_entry.rb', line 58
def self.find(id)
new(Entry.find(id))
end
|
.for_file_usage(usage) ⇒ Object
62
63
64
|
# File 'app/models/pageflow/draft_entry.rb', line 62
def self.for_file_usage(usage)
new(usage.revision.entry)
end
|
Instance Method Details
#create_file!(file_type, attributes) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/models/pageflow/draft_entry.rb', line 17
def create_file!(file_type, attributes)
check_foreign_key_custom_attributes(file_type.custom_attributes, attributes)
file = file_type.model.create!(attributes.except(:configuration)) do |f|
f.entry = entry
end
usage = revision.file_usages.create_with_lock!(file: file,
configuration: attributes[:configuration])
UsedFile.new(file, usage)
end
|
#entry_title ⇒ Object
So we can always get to the original Entry title.
13
14
15
|
# File 'app/models/pageflow/draft_entry.rb', line 13
def entry_title
entry.title
end
|
#remove_file(file) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/pageflow/draft_entry.rb', line 29
def remove_file(file)
draft.file_usages.where(file: 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
50
51
52
|
# File 'app/models/pageflow/draft_entry.rb', line 50
def save!
draft.save!
end
|
#stylesheet_cache_key ⇒ Object
76
77
78
|
# File 'app/models/pageflow/draft_entry.rb', line 76
def stylesheet_cache_key
draft.cache_key
end
|
#stylesheet_model ⇒ Object
72
73
74
|
# File 'app/models/pageflow/draft_entry.rb', line 72
def stylesheet_model
draft
end
|
54
55
56
|
# File 'app/models/pageflow/draft_entry.rb', line 54
def update_meta_data!(attributes)
draft.update!(attributes)
end
|
#use_file(file) ⇒ Object
45
46
47
48
|
# File 'app/models/pageflow/draft_entry.rb', line 45
def use_file(file)
draft.file_usages.create!(file: file.to_model,
configuration: file.configuration)
end
|