Class: Snippets::RepositoryValidationService
- Inherits:
-
Object
- Object
- Snippets::RepositoryValidationService
- Defined in:
- app/services/snippets/repository_validation_service.rb
Constant Summary collapse
- INVALID_REPOSITORY =
:invalid_snippet_repository- SNIPPET_NOT_FOUND =
:snippet_not_found- RepositoryValidationError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#snippet ⇒ Object
readonly
Returns the value of attribute snippet.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(user, snippet) ⇒ RepositoryValidationService
constructor
A new instance of RepositoryValidationService.
Constructor Details
#initialize(user, snippet) ⇒ RepositoryValidationService
Returns a new instance of RepositoryValidationService.
12 13 14 15 16 17 |
# File 'app/services/snippets/repository_validation_service.rb', line 12 def initialize(user, snippet) @current_user = user @snippet = snippet @repository = snippet&.repository end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
8 9 10 |
# File 'app/services/snippets/repository_validation_service.rb', line 8 def current_user @current_user end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
8 9 10 |
# File 'app/services/snippets/repository_validation_service.rb', line 8 def repository @repository end |
#snippet ⇒ Object (readonly)
Returns the value of attribute snippet.
8 9 10 |
# File 'app/services/snippets/repository_validation_service.rb', line 8 def snippet @snippet end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/snippets/repository_validation_service.rb', line 19 def execute return ServiceResponse.error(message: 'No snippet found.', reason: SNIPPET_NOT_FOUND) unless snippet check_branch_count! check_branch_name_default! check_tag_count! check_file_count! check_size! ServiceResponse.success(message: 'Valid snippet repository.') rescue RepositoryValidationError => e ServiceResponse.error(message: "Error: #{e.}", reason: INVALID_REPOSITORY) end |