Misc fixes 2

* Symbolize fact names form the facts files
* Fix Gem versions reporter.

Change-Id: I1a5afaf44d6f75c3485720f819477db5281900bb
This commit is contained in:
Dmitry Ilyin 2016-09-02 11:26:03 -05:00
parent 804ed6db60
commit 0e7a148f48
3 changed files with 14 additions and 1 deletions

View File

@ -77,6 +77,7 @@ module Noop
begin
file_data = YAML.load_file file_path
next unless file_data.is_a? Hash
file_data = Noop::Utils.symbolize_hash_to_keys file_data
facts_data.merge! file_data
rescue
next

View File

@ -35,7 +35,7 @@ Facts hierarchy:
gem = gem.to_s
return unless Object.const_defined? 'Gem'
return unless Gem.loaded_specs.is_a? Hash
return unless Gem.loaded_specs[gem].is_a? Gem::Specification
return unless Gem.loaded_specs[gem].respond_to? :version
Gem.loaded_specs[gem].version
end

View File

@ -104,5 +104,17 @@ module Noop
'=' * 70
end
end
# Convert the top level keys of the hash to Symbols
# @param input_hash [Hash]
# @return [Hash <Symbol => Object>]
def self.symbolize_hash_to_keys(input_hash)
symbolized_hash = {}
input_hash.each do |key, value|
key = key.to_sym if key.respond_to? :to_sym
symbolized_hash[key] = value
end
symbolized_hash
end
end
end