Sha256: 2c4bdf4cbdf97d61bce9112c704ffe8f3905928a54c25f7865686f6c5bfbe460

Contents?: true

Size: 1.8 KB

Versions: 8

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class OsRelease < BaseResolver
      # :pretty_name
      # :name
      # :version_id
      # :version
      # :id
      # :id_like
      # :ansi_color
      # :home_url
      # :support_url
      # :bug_report_url

      @fact_list ||= {}

      class << self
        private

        def post_resolve(fact_name)
          @fact_list.fetch(fact_name) { read_os_release_file(fact_name) }
        end

        def read_os_release_file(fact_name)
          output = Util::FileHelper.safe_readlines('/etc/os-release')
          return @fact_list[:name] = nil if output.empty?

          pairs = []

          output.each do |line|
            pairs << line.strip.delete('"').split('=', 2)
          end

          fill_fact_list(pairs)
          process_name
          pad_version_id
          normalize_opensuse_identifier

          @fact_list[fact_name]
        end

        def fill_fact_list(pairs)
          result = Hash[*pairs.flatten]
          result.each { |k, v| @fact_list[k.downcase.to_sym] = v }

          @fact_list[:identifier] = @fact_list[:id]
        end

        def pad_version_id
          @fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless @fact_list[:version_id] =~ /\./
        end

        def process_name
          return unless @fact_list[:name]

          @fact_list[:name] = if @fact_list[:name].downcase.start_with?('red', 'oracle')
                                @fact_list[:name].split(' ')[0..1].join
                              else
                                @fact_list[:name].split(' ')[0].strip
                              end
        end

        def normalize_opensuse_identifier
          @fact_list[:identifier] = 'opensuse' if @fact_list[:identifier] =~ /opensuse/i
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.43 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.42 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.41 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.40 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.39 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.38 lib/facter/resolvers/os_release_resolver.rb
facter-4.0.37 lib/facter/resolvers/os_release_resolver.rb