Class: KhoinguyenEhTodoList::Services::RemoveTaskService
- Inherits:
-
Object
- Object
- KhoinguyenEhTodoList::Services::RemoveTaskService
- Defined in:
- lib/khoinguyen_eh_todo_list/services/remove_task_service.rb
Overview
Service object to remove a task from the list
Class Method Summary collapse
-
.apply(tasks, memento) ⇒ Object
Re-applies the removal of the task.
- .call(tasks, index) ⇒ Object
-
.revert(tasks, memento) ⇒ Object
Reverts the removal of the task.
Class Method Details
.apply(tasks, memento) ⇒ Object
Re-applies the removal of the task
27 28 29 |
# File 'lib/khoinguyen_eh_todo_list/services/remove_task_service.rb', line 27 def self.apply(tasks, memento) tasks.delete_at(memento.data[:index]) end |
.call(tasks, index) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/khoinguyen_eh_todo_list/services/remove_task_service.rb', line 7 def self.call(tasks, index) index = index.to_i - 1 task = tasks.delete_at(index) raise "Task not found" unless task { success: true, message: "Task removed successfully.", memento: Memento.new(:remove, { index: index, task: task }) } rescue StandardError => e { success: false, error: e. } end |
.revert(tasks, memento) ⇒ Object
Reverts the removal of the task
22 23 24 |
# File 'lib/khoinguyen_eh_todo_list/services/remove_task_service.rb', line 22 def self.revert(tasks, memento) tasks.insert(memento.data[:index], memento.data[:task]) end |