Skip to content

Commit 4b4bee8

Browse files
committed
small maintainability refactor
Fewer `.empty?` checks make it a bit easier to read, and easier to add more local facts if we ever need to. Signed-off-by: Ben Ford <[email protected]>
1 parent ba6b59b commit 4b4bee8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/puppet/node/facts.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ def save(instance, key = nil, options = {})
2929

3030
def add_local_facts(query = [])
3131
query = Array(query) # some use cases result in a nil being passed in
32-
return if query.empty?
32+
local_facts = {
33+
'implementation' => Puppet.implementation,
34+
'clientcert' => Puppet.settings[:certname],
35+
'clientversion' => Puppet.version.to_s,
36+
'clientnoop' => Puppet.settings[:noop],
37+
}
38+
39+
return values.merge!(local_facts) if query.empty?
3340

34-
values["implementation"] = Puppet.implementation if query.include? 'implementation'
35-
values["clientcert"] = Puppet.settings[:certname] if query.include? 'clientcert'
36-
values["clientversion"] = Puppet.version.to_s if query.include? 'clientversion'
37-
values["clientnoop"] = Puppet.settings[:noop] if query.include? 'clientnoop'
41+
local_facts.each do |name, val|
42+
values[name] = val if query.include? name
43+
end
3844
end
3945

4046
def initialize(name, values = {})

0 commit comments

Comments
 (0)