Class: Artisan::Projects::ProjectCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/artisan/projects/project_creator.rb

Constant Summary collapse

WEEK_IN_DAYS =
7

Instance Method Summary collapse

Constructor Details

#initialize(user, callbacks) ⇒ ProjectCreator

Returns a new instance of ProjectCreator.



13
14
15
16
# File 'lib/artisan/projects/project_creator.rb', line 13

def initialize(user, callbacks)
  @user = user
  @callbacks = callbacks
end

Instance Method Details

#create(project_attributes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/artisan/projects/project_creator.rb', line 18

def create(project_attributes)
  api_key = ApiKeyGenerator.unique_api_key
  project_attributes.merge!({api_key: api_key})
  project = repository.new(project_attributes)

  if repository.save(project)
    Activity::ProjectAuditor.created(project.id, @user.id, project_attributes)
    generate_first_iteration_for project
    repository.create_project_configuration(project)
    Teams::Team.new(project, @user).add_team_owner(@user)

    @callbacks.call(:success, project)
  else
    @callbacks.call(:failure, project)
  end

  return project
end