Module: OS
- Defined in:
- lib/atk/os.rb
Overview
Groups
the groups are the pratical side of the OS, they describe the OS rather than fit it prefectly into a heirarchy
Class Method Summary collapse
- .has_command(name_of_executable) ⇒ Object
- .is?(adjective) ⇒ Boolean
- .path_for_executable(name_of_executable) ⇒ Object
-
.version ⇒ Object
TODO: have the version pick one of the verions in the os_heirarchy according to the current OS.
Class Method Details
.has_command(name_of_executable) ⇒ Object
125 126 127 |
# File 'lib/atk/os.rb', line 125 def self.has_command(name_of_executable) return OS.path_for_executable(name_of_executable) != nil end |
.is?(adjective) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/atk/os.rb', line 29 def self.is?(adjective) # summary: # this is a function created for convenience, so it doesn't have to be perfect # you can use it to ask about random qualities of the current OS and get a boolean response # convert to string (if its a symbol) adjective = adjective.to_s.downcase case adjective when 'windows' return (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil when 'mac' return (/darwin/ =~ RUBY_PLATFORM) != nil when 'linux' return (not OS.is?(:windows)) && (not OS.is?(:mac)) when 'unix' return not( OS.is?(:windows)) when 'debian' return File.file?('/etc/debian_version') when 'ubuntu' return OS.has_command('lsb_release') && `lsb_release -a`.match(/Distributor ID:[\s\t]*Ubuntu/) end end |
.path_for_executable(name_of_executable) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/atk/os.rb', line 78 def self.path_for_executable(name_of_executable) program = name_of_executable # this method was extracted from the ptools gem, credit should go to them # https://github.com/djberg96/ptools/blob/master/lib/ptools.rb # this complex method is in favor of just calling the command line because command line calls are slow path=ENV['PATH'] if path.nil? || path.empty? raise ArgumentError, "path cannot be empty" end # Bail out early if an absolute path is provided. if program =~ /^\/|^[a-z]:[\\\/]/i program += WIN32EXTS if MSWINDOWS && File.extname(program).empty? found = Dir[program].first if found && File.executable?(found) && !File.directory?(found) return found else return nil end end # Iterate over each path glob the dir + program. path.split(File::PATH_SEPARATOR).each{ |dir| dir = File.(dir) next unless File.exist?(dir) # In case of bogus second argument file = File.join(dir, program) # Dir[] doesn't handle backslashes properly, so convert them. Also, if # the program name doesn't have an extension, try them all. if MSWINDOWS file = file.tr("\\", "/") file += WIN32EXTS if File.extname(program).empty? end found = Dir[file].first # Convert all forward slashes to backslashes if supported if found && File.executable?(found) && !File.directory?(found) found.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR return found end } return nil end |
.version ⇒ Object
TODO: have the version pick one of the verions in the os_heirarchy according to the current OS
25 26 27 |
# File 'lib/atk/os.rb', line 25 def self.version raise "not yet implemented" end |