Sha256: 3a4275c1eb292ba213edb3be9a937536015e5e997b14d9738f8fc0c74e6a9088

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Macosx
      class Processors < BaseResolver
        @fact_list = {}
        ITEMS = { logical_count: 'hw.logicalcpu_max',
                  physical_count: 'hw.physicalcpu_max',
                  brand: 'machdep.cpu.brand_string',
                  speed: 'hw.cpufrequency_max' }.freeze
        class << self
          # :logicalcount
          # :models
          # :physicalcount
          # :speed

          private

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

          def read_processor_data(fact_name)
            output = Facter::Core::Execution.execute("sysctl #{ITEMS.values.join(' ')}", logger: log)
            build_fact_list(output.split("\n"))
            @fact_list[fact_name]
          end

          def build_fact_list(processors_data)
            build_logical_count(processors_data[0])
            build_physical_count(processors_data[1])
            build_models(processors_data[2])
            build_speed(processors_data[3])
          end

          def build_logical_count(count)
            @fact_list[:logicalcount] = count.split(': ')[1].to_i
          end

          def build_physical_count(count)
            @fact_list[:physicalcount] = count.split(': ')[1].to_i
          end

          def build_models(model)
            brand = model.split(': ').fetch(1)
            @fact_list[:models] = Array.new(@fact_list[:logicalcount].to_i, brand)
          end

          def build_speed(value)
            @fact_list[:speed] = value.split(': ')[1].to_i
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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