Class: Enki::DeletePageUndo

Inherits:
UndoItem
  • Object
show all
Defined in:
app/models/enki/delete_page_undo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_undo(page) ⇒ Object



27
28
29
# File 'app/models/enki/delete_page_undo.rb', line 27

def create_undo(page)
  DeletePageUndo.create!(:data => page.attributes.to_yaml)
end

Instance Method Details

#complete_descriptionObject



22
23
24
# File 'app/models/enki/delete_page_undo.rb', line 22

def complete_description
  "Recreated page '#{loaded_data['title']}'"
end

#descriptionObject



18
19
20
# File 'app/models/enki/delete_page_undo.rb', line 18

def description
  "Deleted page '#{loaded_data['title']}'"
end

#loaded_dataObject



14
15
16
# File 'app/models/enki/delete_page_undo.rb', line 14

def loaded_data
  @loaded_data ||= YAML.load(data)
end

#process!Object



3
4
5
6
7
8
9
10
11
12
# File 'app/models/enki/delete_page_undo.rb', line 3

def process!
  raise('Page already exists') if Page.find_by_id(loaded_data.delete('id').to_i)

  page = nil
  transaction do
    page = Page.create!(loaded_data)
    self.destroy
  end
  page
end