Method: ForemanPuppet::Puppetclass#all_hostgroups

Defined in:
app/models/foreman_puppet/puppetclass.rb

#all_hostgroups(with_descendants: true, unsorted: false) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'app/models/foreman_puppet/puppetclass.rb', line 100

def all_hostgroups(with_descendants: true, unsorted: false)
  hgs = Hostgroup.authorized
                 .left_outer_joins(puppet: [:hostgroup_classes, { config_groups: [:config_group_classes] }])
                 .where("#{id} IN (hostgroup_classes.puppetclass_id, config_group_classes.puppetclass_id)")
                 .distinct
  hgs = hgs.reorder('') if unsorted
  hgs = hgs.flat_map(&:subtree).uniq if with_descendants
  hgs
end