tracks/lib/project_from_todo.rb
Matt Rogers 883ea2b968 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.
2013-05-02 22:30:24 -05:00

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