Class: Snippets::RepositoryValidationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/snippets/repository_validation_service.rb

Constant Summary collapse

RepositoryValidationError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, snippet) ⇒ RepositoryValidationService

Returns a new instance of RepositoryValidationService.


9
10
11
12
13
# File 'app/services/snippets/repository_validation_service.rb', line 9

def initialize(user, snippet)
  @current_user = user
  @snippet = snippet
  @repository = snippet.repository
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


5
6
7
# File 'app/services/snippets/repository_validation_service.rb', line 5

def current_user
  @current_user
end

#repositoryObject (readonly)

Returns the value of attribute repository


5
6
7
# File 'app/services/snippets/repository_validation_service.rb', line 5

def repository
  @repository
end

#snippetObject (readonly)

Returns the value of attribute snippet


5
6
7
# File 'app/services/snippets/repository_validation_service.rb', line 5

def snippet
  @snippet
end

Instance Method Details

#executeObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/snippets/repository_validation_service.rb', line 15

def execute
  if snippet.nil?
    return service_response_error('No snippet found.', 404)
  end

  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.message}", http_status: 400)
end