Sha256: 2fbbef1c08fd38494a489e76681ebc83c865abbe3b147359da1496bf840b2d05

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'win32/registry'

module Facter
  module Resolvers
    class ProductRelease < BaseResolver
      init_resolver

      class << self
        private

        def post_resolve(fact_name, _options)
          @fact_list.fetch(fact_name) { read_fact_from_registry(fact_name) }
        end

        def read_fact_from_registry(fact_name)
          reg = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
          build_fact_list(reg)
          reg.close

          @fact_list[fact_name]
        end

        def build_fact_list(reg)
          reg.each do |name, _type, value|
            case name
            when 'EditionID'
              @fact_list[:edition_id] = value
            when 'InstallationType'
              @fact_list[:installation_type] = value
            when 'ProductName'
              @fact_list[:product_name] = value
            when 'DisplayVersion'
              @fact_list[:release_id] = value
              @fact_list[:display_version] = value
            when 'ReleaseId'
              @fact_list[:release_id] = value unless @fact_list[:release_id]
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/windows/product_release.rb
facter-4.9.0 lib/facter/resolvers/windows/product_release.rb
facter-4.8.0 lib/facter/resolvers/windows/product_release.rb
facter-4.7.1 lib/facter/resolvers/windows/product_release.rb
facter-4.7.0 lib/facter/resolvers/windows/product_release.rb
facter-4.6.1 lib/facter/resolvers/windows/product_release.rb