Class: Enki::DeleteCommentUndo

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_undo(comment) ⇒ Object



28
29
30
# File 'app/models/enki/delete_comment_undo.rb', line 28

def create_undo(comment)
  DeleteCommentUndo.create!(:data => comment.attributes.to_yaml)
end

Instance Method Details

#complete_descriptionObject



23
24
25
# File 'app/models/enki/delete_comment_undo.rb', line 23

def complete_description
  "Recreated comment by '#{loaded_data['author']}'"
end

#descriptionObject



19
20
21
# File 'app/models/enki/delete_comment_undo.rb', line 19

def description
  "Deleted comment by '#{loaded_data['author']}'"
end

#loaded_dataObject



15
16
17
# File 'app/models/enki/delete_comment_undo.rb', line 15

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

#process!Object

Raises:



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

def process!
  raise(UndoFailed) if Comment.find_by_id(loaded_data.delete('id').to_i)

  comment = nil
  transaction do
    comment = Comment.create(loaded_data)
    raise UndoFailed if comment.new_record?
    self.destroy
  end
  comment
end