Class: OsDetector

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/framework/detector/os_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ OsDetector

Returns a new instance of OsDetector.



10
11
12
13
# File 'lib/framework/detector/os_detector.rb', line 10

def initialize(*_args)
  @identifier = detect
  @hierarchy = create_hierarchy(@identifier)
end

Instance Attribute Details

#hierarchyObject (readonly)

Returns the value of attribute hierarchy.



8
9
10
# File 'lib/framework/detector/os_detector.rb', line 8

def hierarchy
  @hierarchy
end

#identifierObject (readonly)

Returns the value of attribute identifier.



8
9
10
# File 'lib/framework/detector/os_detector.rb', line 8

def identifier
  @identifier
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/framework/detector/os_detector.rb', line 8

def version
  @version
end

Instance Method Details

#detectObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/framework/detector/os_detector.rb', line 15

def detect
  host_os = RbConfig::CONFIG['host_os']
  @identifier = case host_os
                when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
                  :windows
                when /darwin|mac os/
                  :macosx
                when /linux/
                  detect_distro
                when /bsd/
                  :bsd
                when /solaris/
                  :solaris
                when /aix/
                  :aix
                else
                  raise "unknown os: #{host_os.inspect}"
                end
end