Class: Facter::OsHierarchy
- Inherits:
-
Object
- Object
- Facter::OsHierarchy
- Defined in:
- lib/facter/framework/detector/os_hierarchy.rb
Instance Method Summary collapse
- #construct_hierarchy(searched_os) ⇒ Object
-
#initialize ⇒ OsHierarchy
constructor
A new instance of OsHierarchy.
Constructor Details
#initialize ⇒ OsHierarchy
Returns a new instance of OsHierarchy.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/facter/framework/detector/os_hierarchy.rb', line 5 def initialize @log = Log.new(self) json_file_path = File.join(File.dirname(__FILE__), '../../os_hierarchy.json') json_file = Util::FileHelper.safe_read(json_file_path) begin @json_os_hierarchy = JSON.parse(json_file) rescue JSON::ParserError => _e @log.error('Could not parse os_hierarchy json') end end |
Instance Method Details
#construct_hierarchy(searched_os) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/facter/framework/detector/os_hierarchy.rb', line 16 def construct_hierarchy(searched_os) return [] if searched_os.nil? searched_os = searched_os.to_s.capitalize if @json_os_hierarchy.nil? @log.debug("There is no os_hierarchy, will fall back to: #{searched_os}") return [searched_os] end @searched_path = [] search(@json_os_hierarchy, searched_os, []) @searched_path.map { |os_name| os_name.to_s.capitalize } end |