Class: Pageflow::DraftEntry
- Inherits:
-
Object
- Object
- Pageflow::DraftEntry
- Includes:
- ActiveModel::Conversion
- Defined in:
- app/models/pageflow/draft_entry.rb
Instance Attribute Summary collapse
-
#draft ⇒ Object
readonly
Returns the value of attribute draft.
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
Class Method Summary collapse
Instance Method Summary collapse
- #create_file!(model, attributes) ⇒ Object
-
#entry_title ⇒ Object
So we can always get to the original Entry title.
- #home_button ⇒ Object
-
#initialize(entry, draft = nil) ⇒ DraftEntry
constructor
A new instance of DraftEntry.
- #overview_button ⇒ Object
- #remove_file(file) ⇒ Object
- #resolve_widgets(options = {}) ⇒ Object
- #save! ⇒ Object
- #stylesheet_cache_key ⇒ Object
- #stylesheet_model ⇒ Object
- #update_meta_data!(attributes) ⇒ Object
- #use_file(file) ⇒ Object
Constructor Details
#initialize(entry, draft = nil) ⇒ DraftEntry
Returns a new instance of DraftEntry.
31 32 33 34 |
# File 'app/models/pageflow/draft_entry.rb', line 31 def initialize(entry, draft = nil) @entry = entry @draft = draft || entry.draft end |
Instance Attribute Details
#draft ⇒ Object (readonly)
Returns the value of attribute draft.
5 6 7 |
# File 'app/models/pageflow/draft_entry.rb', line 5 def draft @draft end |
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
5 6 7 |
# File 'app/models/pageflow/draft_entry.rb', line 5 def entry @entry end |
Class Method Details
.accessible_by(ability, action) ⇒ Object
87 88 89 90 91 |
# File 'app/models/pageflow/draft_entry.rb', line 87 def self.accessible_by(ability, action) Entry.includes(:draft).accessible_by(ability, action).map do |entry| DraftEntry.new(entry) end end |
.find(id) ⇒ Object
79 80 81 |
# File 'app/models/pageflow/draft_entry.rb', line 79 def self.find(id) new(Entry.find(id)) end |
.for_file_usage(usage) ⇒ Object
83 84 85 |
# File 'app/models/pageflow/draft_entry.rb', line 83 def self.for_file_usage(usage) new(usage.revision.entry) end |
Instance Method Details
#create_file!(model, attributes) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'app/models/pageflow/draft_entry.rb', line 41 def create_file!(model, attributes) file = model.create!(attributes.except(:configuration)) do |f| f.entry = entry end usage = @draft.file_usages.create(file: file, configuration: attributes[:configuration]) UsedFile.new(file, usage) end |
#entry_title ⇒ Object
So we can always get to the original Entry title.
37 38 39 |
# File 'app/models/pageflow/draft_entry.rb', line 37 def entry_title entry.title end |
#home_button ⇒ Object
101 102 103 |
# File 'app/models/pageflow/draft_entry.rb', line 101 def HomeButton.new(draft, theming) end |
#overview_button ⇒ Object
105 106 107 |
# File 'app/models/pageflow/draft_entry.rb', line 105 def OverviewButton.new(draft) end |
#remove_file(file) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/pageflow/draft_entry.rb', line 50 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 |
#resolve_widgets(options = {}) ⇒ Object
109 110 111 |
# File 'app/models/pageflow/draft_entry.rb', line 109 def ( = {}) .resolve(Pageflow.config_for(entry), ) end |
#save! ⇒ Object
71 72 73 |
# File 'app/models/pageflow/draft_entry.rb', line 71 def save! draft.save! end |
#stylesheet_cache_key ⇒ Object
97 98 99 |
# File 'app/models/pageflow/draft_entry.rb', line 97 def stylesheet_cache_key draft.cache_key end |
#stylesheet_model ⇒ Object
93 94 95 |
# File 'app/models/pageflow/draft_entry.rb', line 93 def stylesheet_model draft end |
#update_meta_data!(attributes) ⇒ Object
75 76 77 |
# File 'app/models/pageflow/draft_entry.rb', line 75 def (attributes) draft.update_attributes!(attributes) end |
#use_file(file) ⇒ Object
66 67 68 69 |
# File 'app/models/pageflow/draft_entry.rb', line 66 def use_file(file) draft.file_usages.create!(file: file.to_model, configuration: file.configuration) end |