Sha256: d8c32cac2fbb1f20012eb3e1ed5e90aa6566dbc216652a750ce20cebeeeab02b

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Macosx
      class Processors < BaseResolver
        @semaphore = Mutex.new
        @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

15 entries across 15 versions & 1 rubygems

Version Path
facter-4.0.36 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.35 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.34 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.33 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.32 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.31 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.30 lib/facter/resolvers/macosx/processor_resolver.rb
facter-4.0.29 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.28 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.26 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.25 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.24 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.23 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.22 lib/resolvers/macosx/processor_resolver.rb
facter-4.0.21 lib/resolvers/macosx/processor_resolver.rb