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
- #add_file(file) ⇒ Object
- #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
Constructor Details
#initialize(entry, draft = nil) ⇒ DraftEntry
Returns a new instance of DraftEntry.
27 28 29 30 |
# File 'app/models/pageflow/draft_entry.rb', line 27 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
73 74 75 76 77 |
# File 'app/models/pageflow/draft_entry.rb', line 73 def self.accessible_by(ability, action) Entry.includes(:draft).accessible_by(ability, action).map do |entry| DraftEntry.new(entry) end end |
.find(id) ⇒ Object
65 66 67 |
# File 'app/models/pageflow/draft_entry.rb', line 65 def self.find(id) new(Entry.find(id)) end |
.for_file_usage(usage) ⇒ Object
69 70 71 |
# File 'app/models/pageflow/draft_entry.rb', line 69 def self.for_file_usage(usage) new(usage.revision.entry) end |
Instance Method Details
#add_file(file) ⇒ Object
53 54 55 |
# File 'app/models/pageflow/draft_entry.rb', line 53 def add_file(file) draft.file_usages.create!(:file => file) end |
#create_file(model, attributes) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/pageflow/draft_entry.rb', line 37 def create_file(model, attributes) file = model.create(attributes) do |f| f.entry = entry end usage = @draft.file_usages.create(:file => file) file.usage_id = usage.id file end |
#entry_title ⇒ Object
So we can always get to the original Entry title.
33 34 35 |
# File 'app/models/pageflow/draft_entry.rb', line 33 def entry_title entry.title end |
#home_button ⇒ Object
87 88 89 |
# File 'app/models/pageflow/draft_entry.rb', line 87 def HomeButton.new(draft, theming) end |
#overview_button ⇒ Object
91 92 93 |
# File 'app/models/pageflow/draft_entry.rb', line 91 def OverviewButton.new(draft, theming) end |
#remove_file(file) ⇒ Object
48 49 50 51 |
# File 'app/models/pageflow/draft_entry.rb', line 48 def remove_file(file) draft.file_usages.where(file: file).destroy_all file.destroy if file.usages.empty? end |
#resolve_widgets(options = {}) ⇒ Object
95 96 97 |
# File 'app/models/pageflow/draft_entry.rb', line 95 def ( = {}) .resolve(Pageflow.config_for(entry), ) end |
#save! ⇒ Object
57 58 59 |
# File 'app/models/pageflow/draft_entry.rb', line 57 def save! draft.save! end |
#stylesheet_cache_key ⇒ Object
83 84 85 |
# File 'app/models/pageflow/draft_entry.rb', line 83 def stylesheet_cache_key draft.cache_key end |
#stylesheet_model ⇒ Object
79 80 81 |
# File 'app/models/pageflow/draft_entry.rb', line 79 def stylesheet_model draft end |
#update_meta_data!(attributes) ⇒ Object
61 62 63 |
# File 'app/models/pageflow/draft_entry.rb', line 61 def (attributes) draft.update_attributes!(attributes) end |