Class: ForemanParamLookup::AnyClassification

Inherits:
Classification::ClassParam
  • Object
show all
Includes:
HostsHelper, LookupKeysHelper
Defined in:
app/services/foreman_param_lookup/any_classification.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = { }) ⇒ AnyClassification

Returns a new instance of AnyClassification.



5
6
7
8
# File 'app/services/foreman_param_lookup/any_classification.rb', line 5

def initialize args = { }
  super args
  @classes = args[:classes]
end

Instance Method Details

#encObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/foreman_param_lookup/any_classification.rb', line 10

def enc
  hash = @classes.map do |puppet_class|
    lookup_keys   = overridable_lookup_keys(puppet_class, @host)
    lookup_values = lookup_keys.map { |lookup_key|
    
      if lookup_key.use_puppet_default
        value = lookup_key.default_value
      else
        lookup_value = @host.lookup_values.detect { |v| v.lookup_key_id == lookup_key.id }
        value = lookup_value.value unless lookup_value.nil?
      end

      [lookup_key.key, value]
    }.compact

    [puppet_class.name, Hash[lookup_values]] unless lookup_values.empty?
  end

  Hash[hash.compact]
end