Class: Snippets::CountService

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

Instance Method Summary collapse

Constructor Details

#initialize(current_user, author: nil, project: nil) ⇒ CountService

Returns a new instance of CountService.



37
38
39
40
41
42
43
44
45
# File 'app/services/snippets/count_service.rb', line 37

def initialize(current_user, author: nil, project: nil)
  if !author && !project
    raise(
      ArgumentError, 'Must provide either an author or a project'
    )
  end

  @snippets_finder = SnippetsFinder.new(current_user, author: author, project: project)
end

Instance Method Details

#executeObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/snippets/count_service.rb', line 47

def execute
  counts = snippet_counts
  return {} unless counts

  counts.slice(
    :are_public,
    :are_private,
    :are_internal,
    :are_public_or_internal,
    :total
  )
end