Sha256: 258f53e0b12a71d9a6287ffc0268c9d71226fa9c426484e9a2935a7bb744ce4b

Contents?: true

Size: 874 Bytes

Versions: 8

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

module Facter
  class ClassDiscoverer
    include Singleton

    def initialize
      @log = Log.new(self)
    end

    def discover_classes(operating_system)
      os_module_name = Module.const_get("Facts::#{operating_system}")

      # select only classes
      find_nested_classes(os_module_name, discovered_classes = [])
      discovered_classes
    rescue NameError
      @log.debug("There is no module named #{operating_system}")
      []
    end

    def find_nested_classes(mod, discovered_classes)
      mod.constants.each do |constant_name|
        obj = mod.const_get(constant_name)
        if obj.instance_of? Class
          discovered_classes << obj
        elsif obj.instance_of? Module
          find_nested_classes(Module.const_get("#{mod.name}::#{constant_name}"), discovered_classes)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.9.0 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.8.0 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.7.1 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.7.0 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.6.1 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.6.0 lib/facter/framework/core/fact_loaders/class_discoverer.rb
facter-4.5.2 lib/facter/framework/core/fact_loaders/class_discoverer.rb