Class: Import::GitlabProjects::CreateProjectService

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Services::ReturnServiceResponses
Defined in:
app/services/import/gitlab_projects/create_project_service.rb

Instance Method Summary collapse

Methods included from Services::ReturnServiceResponses

#success

Constructor Details

#initialize(current_user, params:, file_acquisition_strategy: FileAcquisitionStrategies::FileUpload) ⇒ CreateProjectService

Creates a new CreateProjectService.

Parameters:



20
21
22
23
24
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 20

def initialize(current_user, params:, file_acquisition_strategy: FileAcquisitionStrategies::FileUpload)
  @current_user = current_user
  @params = params.dup
  @strategy = file_acquisition_strategy.new(current_user: current_user, params: params)
end

Instance Method Details

#errorsObject

Merge with strategy’s errors



44
45
46
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 44

def errors
  super.tap { _1.merge!(strategy.errors) }
end

#executeServices::ServiceReponse

Creates a project with the strategy parameters

Returns:

  • (Services::ServiceReponse)


29
30
31
32
33
34
35
36
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 29

def execute
  return error(errors.full_messages) unless valid?
  return error(project.errors.full_messages) unless project.saved?

  success(project)
rescue StandardError => e
  error(e.message)
end

#read_attribute_for_validation(key) ⇒ Object



48
49
50
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 48

def read_attribute_for_validation(key)
  params[key]
end

#valid?Boolean

Cascade the validation to strategy

Returns:

  • (Boolean)


39
40
41
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 39

def valid?
  super && strategy.valid?
end