class ActiveScripts::OperatingSystem

Constants

OPERATING_SYSTEMS

INFO: ActiveScripts::OperatingSystem contains code that is

for retrieving and validating operating systems.

Attributes

operating_system[RW]

Public Class Methods

find() click to toggle source
# File lib/active_scripts/operating_system.rb, line 18
def self.find
  new.find
end
new() click to toggle source
# File lib/active_scripts/operating_system.rb, line 14
def initialize
  @operating_system = :unknown
end

Public Instance Methods

find() click to toggle source
# File lib/active_scripts/operating_system.rb, line 22
def find
  generate_operating_system!
  assert_valid_operating_system!
  return(@operating_system)
end

Private Instance Methods

assert_valid_operating_system!() click to toggle source
# File lib/active_scripts/operating_system.rb, line 30
def assert_valid_operating_system!
  unless OPERATING_SYSTEMS.include?(@operating_system)
    raise ArgumentError,
      "Unknown operating system: #{@operating_system.inspect}. Valid operating systems are: #{OPERATING_SYSTEMS.map(&:inspect).join(', ')}"
  end
end
generate_operating_system!() click to toggle source
# File lib/active_scripts/operating_system.rb, line 37
def generate_operating_system!
  host_os = RbConfig::CONFIG['host_os']

  @operating_system = case host_os
  when /freebsd/
    :freebsd
  when /linux/
    :linux
  when /darwin|mac os|mac os x/
    :macosx
  when /solaris|bsd/
    :unix
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    :windows
  else
    ask("== Which operating system? ", lambda { |str| str.strip.downcase.to_sym })
  end
end