Class: Import::GitlabProjects::CreateProjectService
- Inherits:
-
Object
- Object
- Import::GitlabProjects::CreateProjectService
- Includes:
- ActiveModel::Validations, Services::ReturnServiceResponses
- Defined in:
- app/services/import/gitlab_projects/create_project_service.rb
Instance Method Summary collapse
-
#errors ⇒ Object
Merge with strategy’s errors.
-
#execute ⇒ Services::ServiceResponse
Creates a project with the strategy parameters.
-
#initialize(current_user, params:, file_acquisition_strategy: FileAcquisitionStrategies::FileUpload) ⇒ CreateProjectService
constructor
Creates a new CreateProjectService.
- #read_attribute_for_validation(key) ⇒ Object
-
#valid? ⇒ Boolean
Cascade the validation to strategy.
Methods included from Services::ReturnServiceResponses
Constructor Details
#initialize(current_user, params:, file_acquisition_strategy: FileAcquisitionStrategies::FileUpload) ⇒ CreateProjectService
Creates a new CreateProjectService.
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
#errors ⇒ Object
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 |
#execute ⇒ Services::ServiceResponse
Creates a project with the strategy parameters
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.) unless valid? return error(project.errors.) unless project.saved? success(project) rescue StandardError => e error(e.) 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
39 40 41 |
# File 'app/services/import/gitlab_projects/create_project_service.rb', line 39 def valid? super && strategy.valid? end |