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:
Matt Rogers 2013-05-02 22:29:21 -05:00
parent 18883c6ecc
commit 883ea2b968
5 changed files with 50 additions and 24 deletions

27
lib/project_from_todo.rb Normal file
View 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