mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00

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.
27 lines
425 B
Ruby
27 lines
425 B
Ruby
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
|