Class: Snippets::UpdateStatisticsService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snippet) ⇒ UpdateStatisticsService

Returns a new instance of UpdateStatisticsService.



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

def initialize(snippet)
  @snippet = snippet
end

Instance Attribute Details

#snippetObject (readonly)

Returns the value of attribute snippet.



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

def snippet
  @snippet
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
# File 'app/services/snippets/update_statistics_service.rb', line 11

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

  snippet.repository.expire_statistics_caches
  statistics.refresh!

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