mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-01 23:08:49 +01:00
Move Project#create_from_todo to its own class
The point of this is to keep as many things out of the ActiveRecord objects as possible and use them as just a thin database abstraction layer.
This commit is contained in:
parent
18883c6ecc
commit
883ea2b968
5 changed files with 50 additions and 24 deletions
27
lib/project_from_todo.rb
Normal file
27
lib/project_from_todo.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
class ProjectFromTodo
|
||||
attr_reader :todo
|
||||
|
||||
def initialize(todo)
|
||||
@todo = todo
|
||||
end
|
||||
|
||||
def create
|
||||
project = build_project
|
||||
|
||||
if project.valid?
|
||||
todo.destroy
|
||||
project.save!
|
||||
end
|
||||
|
||||
project
|
||||
end
|
||||
|
||||
def build_project
|
||||
project = Project.new.tap do |p|
|
||||
p.name = todo.description
|
||||
p.description = todo.notes
|
||||
p.default_context = todo.context
|
||||
p.user = todo.user
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue