class FeduxOrgStdlib::SupportInformation

Gather support information

@example Gather information

info = SupportInformation.new puts info

Attributes

headlines[R]
logger[R]
underline_character[R]

Public Class Methods

new(logger: FeduxOrgStdlib::Logging::Logger.new, headlines: {}, underline_character: '-') click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 20
def initialize(logger: FeduxOrgStdlib::Logging::Logger.new, headlines: {}, underline_character: '-')
  @logger              = logger
  @headlines           = headlines
  @underline_character = underline_character
end

Public Instance Methods

to_s() click to toggle source

Output support information as string

@return [String]

The available information
# File lib/fedux_org_stdlib/support_information.rb, line 30
def to_s
  result = []

  max_field_length = determine_max_field_length(facter_fields)

  result << headlines.fetch(:system_information, 'System Information').underline(character: underline_character)
  result << format("%#{max_field_length}s | %s", 'Information', 'Value')
  result << format('%s + %s', '-' * max_field_length, '-' * 40)
  result.concat system_information.sort_by { |key, _value| key }.map { |key, value| format("%#{max_field_length}s | %s", key, value) }

  result << ''
  result << ''
  result << ''

  max_field_length = determine_max_field_length(rubygems_information.keys)

  result << headlines.fetch(:rubygems_information, 'Rubygems Information').underline(character: underline_character)
  result << format("%#{max_field_length}s | %s", 'Information', 'Value')
  result << format('%s + %s', '-' * max_field_length, '-' * 40)
  result.concat rubygems_information.sort_by { |key, _value| key }.map { |key, value| format("%#{max_field_length}s | %s", key, value) }

  result << ''
  result << ''
  result << ''

  max_field_length = determine_max_field_length(installed_rubygems.keys)

  result << headlines.fetch(:installed_rubygems, 'Installed Rubygems').underline(character: underline_character)
  result << format("%#{max_field_length}s | %s", 'Name', 'version')
  result << format('%s + %s', '-' * max_field_length, '-' * 40)
  result.concat installed_rubygems.sort_by { |key, _value| key }.map { |key, value| format("%#{max_field_length}s | %s", key, value) }

  result.join "\n"
end

Private Instance Methods

determine_max_field_length(list) click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 93
def determine_max_field_length(list)
  list.reduce(0) { |a, e| e.size > a ? e.size : a }
end
facter_fields() click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 97
def facter_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
installed_rubygems() click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 77
def installed_rubygems
  result = {}
  Gem::Specification.find_all.each_with_object(result) { |e, a| a[e.name] = e.version }

  result
end
rubygems_information() click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 67
def rubygems_information
  result = {}
  result[:ruby] = Gem.ruby
  result[:ruby_engine] = Gem.ruby_engine
  result[:ruby_api_version] = Gem.ruby_engine
  result[:rubygems_version] = Gem.rubygems_version

  result
end
system_information() click to toggle source
# File lib/fedux_org_stdlib/support_information.rb, line 84
def system_information
  Timeout.timeout(10) do
    Facter.to_hash.keep_if { |key, _| facter_fields.include?(key.to_s) }
  end
rescue Timeout::Error
  logger.warn 'Getting environment information took to long. Please make sure the name resolver is available. This might cause the latency.'
  {}
end