Class: Groups::UpdateStatisticsService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, statistics: []) ⇒ UpdateStatisticsService

Returns a new instance of UpdateStatisticsService.



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

def initialize(group, statistics: [])
  @group = group
  @statistics = statistics
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



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

def group
  @group
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



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

def statistics
  @statistics
end

Instance Method Details

#executeObject



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

def execute
  unless group
    return ServiceResponse.error(message: 'Invalid group', http_status: 400)
  end

  namespace_statistics.refresh!(only: statistics.map(&:to_sym))

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