Sha256: bac8f160ae8fb08d25bae456c9e266c798b9552ccf2b707bddf90334dce507c1

Contents?: true

Size: 906 Bytes

Versions: 10

Compression:

Stored size: 906 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.error("There is no module named #{operating_system}")
      []
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facter-4.0.18 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.17 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.16 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.15 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.14 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.13 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.12 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.11 lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.10.pre lib/framework/core/fact_loaders/class_discoverer.rb
facter-4.0.9.pre lib/framework/core/fact_loaders/class_discoverer.rb