Sha256: e171230b2b26c2767abe9f7bdb3e1bb586e245a96e81747a5123cfbe53efa3e7

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

# encoding: utf-8
module LocalPac
  module Actions
    class GetSystemInformation
      private

      attr_reader :options

      public

      def initialize(options = {})
        @options = options
      end

      def run
        printf( "%#{max_field_length}s | %s\n", 'Information', 'Value')
        printf( "%s + %s\n", '-' * max_field_length, '-' * 40)
        data.sort_by { |key, value| key }.each { |key, value| printf( "%#{max_field_length}s | %s\n", key, value) }
      end

      private

      def data
        Timeout::timeout(5) do
          Facter.to_hash.keep_if { |key,_| fields.include?(key.to_s) }
        end
      rescue Timeout::Error
        LocalPac.ui_logger.warn 'Getting environment information took to long. Please make sure the name resolver is avaiable. This might cause the latency.'
        {}
      end

      def max_field_length
        fields.inject(0) { |memo, f| memo = f.size if f.size > memo ; memo}
      end

      def fields
        %w[
            architecture 
            filesystems 
            hardwareisa 
            hardwaremodel 
            is_virtual 
            kernel 
            kernelmajversion 
            kernelrelease 
            kernelversion 
            memoryfree 
            memoryfree_mb 
            memorysize 
            memorysize_mb 
            memorytotal 
            operatingsystem 
            operatingsystemrelease 
            osfamily 
            path 
            physicalprocessorcount 
            processor0 
            processor1 
            processorcount 
            ps 
            rubysitedir 
            rubyversion 
            selinux 
            swapfree 
            swapfree_mb 
            swapsize 
            swapsize_mb 
            timezone 
            uptime 
            uptime_days 
            uptime_hours 
            uptime_seconds 
            virtual 
        ]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
local_pac-0.5.0 lib/local_pac/actions/get_system_information.rb
local_pac-0.4.0 lib/local_pac/actions/get_system_information.rb
local_pac-0.3.0 lib/local_pac/actions/get_system_information.rb
local_pac-0.2.3 lib/local_pac/actions/get_system_information.rb
local_pac-0.2.2 lib/local_pac/actions/get_system_information.rb
local_pac-0.2.1 lib/local_pac/actions/get_system_information.rb
local_pac-0.2.0 lib/local_pac/actions/get_system_information.rb