Sha256: c85d0cd5f9a9568a42495ccb6ab260eca46782d8c0781a4fec68ef9623fe9ac9

Contents?: true

Size: 1.63 KB

Versions: 10

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Facts
  module Macosx
    module Os
      module Macosx
        class Version
          FACT_NAME = 'os.macosx.version'
          ALIASES = %w[macosx_productversion macosx_productversion_major macosx_productversion_minor
                       macosx_productversion_patch].freeze

          def call_the_resolver
            version_value = Facter::Resolvers::SwVers.resolve(:productversion)
            extra_value = Facter::Resolvers::SwVers.resolve(:productversionextra)
            ver = version_hash(version_value, extra_value)

            [Facter::ResolvedFact.new(FACT_NAME, ver),
             Facter::ResolvedFact.new(ALIASES[0], version_value, :legacy),
             Facter::ResolvedFact.new(ALIASES[1], ver['major'], :legacy),
             Facter::ResolvedFact.new(ALIASES[2], ver['minor'], :legacy),
             Facter::ResolvedFact.new(ALIASES[3], ver['patch'], :legacy)]
          end

          def version_hash(version_value, extra_value)
            versions = version_value.split('.')
            if versions[0] == '10'
              { 'full' => version_value, 'major' => "#{versions[0]}.#{versions[1]}", 'minor' => versions[-1] }
            elsif /11|12/.match?(versions[0]) || extra_value.nil?
              { 'full' => version_value, 'major' => versions[0], 'minor' => versions.fetch(1, '0'),
                'patch' => versions.fetch(2, '0') }
            else
              { 'full' => version_value, 'major' => versions[0], 'minor' => versions.fetch(1, '0'),
                'patch' => versions.fetch(2, '0'), 'extra' => extra_value }
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.9.0 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.8.0 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.7.1 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.7.0 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.6.1 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.6.0 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.5.2 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.5.1 lib/facter/facts/macosx/os/macosx/version.rb
facter-4.5.0 lib/facter/facts/macosx/os/macosx/version.rb