Class: Snippets::UpdateStatisticsService

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

Constant Summary collapse

REPOSITORY_NOT_FOUND =
:repository_not_found

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snippet) ⇒ UpdateStatisticsService

Returns a new instance of UpdateStatisticsService.



9
10
11
# File 'app/services/snippets/update_statistics_service.rb', line 9

def initialize(snippet)
  @snippet = snippet
end

Instance Attribute Details

#snippetObject (readonly)

Returns the value of attribute snippet.



7
8
9
# File 'app/services/snippets/update_statistics_service.rb', line 7

def snippet
  @snippet
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/snippets/update_statistics_service.rb', line 13

def execute
  unless snippet.repository_exists?
    return ServiceResponse.error(
      message: 'Invalid snippet repository',
      reason: REPOSITORY_NOT_FOUND
    )
  end

  snippet.repository.expire_statistics_caches
  statistics.refresh!

  ServiceResponse.success(message: 'Snippet statistics successfully updated.')
end