Class: ForemanPuppet::HostgroupPuppetFacet
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanPuppet::HostgroupPuppetFacet
show all
- Includes:
- Facets::HostgroupFacet, PuppetFacetCommon
- Defined in:
- app/models/foreman_puppet/hostgroup_puppet_facet.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#all_puppetclass_ids, #available_puppetclasses, #cg_class_ids, #classes, #classes_in_groups, #hg_class_ids, #host_class_ids, #individual_puppetclasses, #parent_name, #puppetclass_ids
Class Attribute Details
.nested_attribute_fields ⇒ Object
Returns the value of attribute nested_attribute_fields.
7
8
9
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 7
def nested_attribute_fields
@nested_attribute_fields
end
|
Class Method Details
.nested_attribute_for(*fields) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 9
def nested_attribute_for(*fields)
@nested_attribute_fields ||= []
@nested_attribute_fields |= fields
@nested_attribute_fields.each do |field|
define_method "inherited_#{field}" do
self[field] || nested(field)
end
next unless (md = field.to_s.match(/(\w+)_id$/))
define_method md[1] do
if hostgroup.ancestry.present?
klass = "ForemanPuppet::#{md[1].classify}"
klass = 'SmartProxy' if md[1] == 'puppet_proxy' || md[1] == 'puppet_ca_proxy'
klass = 'Subnet::Ipv4' if md[1] == 'subnet'
klass = 'Subnet::Ipv6' if md[1] == 'subnet6'
klass.constantize.find_by(id: send("inherited_#{field}"))
else
super()
end
end
end
end
|
Instance Method Details
#all_config_groups ⇒ Object
76
77
78
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 76
def all_config_groups
(config_groups + parent_config_groups).uniq
end
|
#nested(attr) ⇒ Object
46
47
48
49
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 46
def nested(attr)
return nil if hostgroup.ancestry.blank?
Hostgroup.sort_by_ancestry(hostgroup.ancestors.joins(:puppet).where(HostgroupPuppetFacet.arel_table[attr.to_sym].not_eq(nil))).last&.puppet.try(attr)
end
|
#parent_classes ⇒ Object
the environment used by #clases nees to be self.environment and not self.parent.environment
90
91
92
93
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 90
def parent_classes
return [] unless parent_facet
parent_facet.classes(environment)
end
|
#parent_config_groups ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 80
def parent_config_groups
return [] unless hostgroup.parent
groups = []
hostgroup.ancestors.each do |hostgroup|
groups += hostgroup.puppet&.config_groups || []
end
groups.uniq
end
|
#parent_facet ⇒ Object
58
59
60
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 58
def parent_facet
@parent_facet ||= hostgroup.parent_id && HostgroupPuppetFacet.find_by(hostgroup_id: hostgroup.parent_id)
end
|
#parent_facet_id ⇒ Object
54
55
56
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 54
def parent_facet_id
parent_facet&.id
end
|
#remove_duplicated_nested_class ⇒ Object
95
96
97
98
|
# File 'app/models/foreman_puppet/hostgroup_puppet_facet.rb', line 95
def remove_duplicated_nested_class
ancestor_hgs = hostgroup.ancestors.preload(puppet: :puppetclasses)
self.puppetclasses -= ancestor_hgs.map { |ancestor| ancestor.puppet&.puppetclasses }.compact.flatten
end
|