Class: ForemanStatistics::Statistics::CountPuppetClasses

Inherits:
Base
  • Object
show all
Defined in:
app/services/foreman_statistics/statistics/count_puppet_classes.rb

Instance Attribute Summary

Attributes inherited from Base

#count_by, #title, #url

Instance Method Summary collapse

Methods inherited from Base

#id, #metadata, #search

Constructor Details

#initialize(options = {}) ⇒ CountPuppetClasses

Returns a new instance of CountPuppetClasses.



4
5
6
7
8
9
# File 'app/services/foreman_statistics/statistics/count_puppet_classes.rb', line 4

def initialize(options = {})
  super(options)
  if id.empty?
    raise(ArgumentError, 'Must provide an :id or :count_by option')
  end
end

Instance Method Details

#calculateObject



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

def calculate
  ForemanPuppet::Puppetclass.authorized(:view_puppetclasses).map do |pc|
    count = pc.hosts_count
    next if count.zero?
    {
      :label => pc.to_label,
      :data => count
    }
  end.compact
end