Module: Filament::OS
- Defined in:
- lib/filament/os.rb
Constant Summary collapse
- TARGET_PLATFORMS =
{}
Instance Method Summary collapse
- #cygwin? ⇒ Boolean
- #darwin? ⇒ Boolean
- #fix_paths(paths) ⇒ Object (also: #fix)
- #join_paths(paths) ⇒ Object
- #sys(c) ⇒ Object
- #to_exec_path(path) ⇒ Object
- #to_unix_path(path) ⇒ Object (also: #u)
- #to_windows_path(path) ⇒ Object (also: #w)
- #windows? ⇒ Boolean
Instance Method Details
#cygwin? ⇒ Boolean
12 13 14 |
# File 'lib/filament/os.rb', line 12 def cygwin? return ! PLATFORM.index("cygwin").nil? end |
#darwin? ⇒ Boolean
4 5 6 |
# File 'lib/filament/os.rb', line 4 def darwin? return ! PLATFORM.index("darwin").nil? end |
#fix_paths(paths) ⇒ Object Also known as: fix
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/filament/os.rb', line 51 def fix_paths(paths) return nil if paths.nil? if cygwin? paths = paths.to_a.collect do |path| to_windows_path(path) end end return paths.to_a end |
#join_paths(paths) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/filament/os.rb', line 63 def join_paths(paths) return nil if paths.nil? if windows? joined = fix_paths(paths).join(';') return "'#{joined}'" end return fix_paths(paths).join(':') end |
#sys(c) ⇒ Object
16 17 18 19 |
# File 'lib/filament/os.rb', line 16 def sys(c) log c raise "!!! Error executing '#{c}'" unless system(c) end |
#to_exec_path(path) ⇒ Object
32 33 34 35 36 |
# File 'lib/filament/os.rb', line 32 def to_exec_path(path) return nil if path.nil? return to_unix_path(path) if cygwin? return path end |
#to_unix_path(path) ⇒ Object Also known as: u
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/filament/os.rb', line 21 def to_unix_path(path) return nil if path.nil? if cygwin? return path unless /:\\/ === path drive, path = path.split(":\\", 2) path.gsub!(/\\/, '/') return "/cygdrive/#{drive}/#{path}" end return path end |
#to_windows_path(path) ⇒ Object Also known as: w
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/filament/os.rb', line 38 def to_windows_path(path) return nil if path.nil? if path.index('cygdrive').nil? puts "#{path}\n" return path end path = path.chomp.sub(/\/cygdrive\//, '') drive, path = path.split(/\//, 2) return "#{drive}:/#{path}" end |
#windows? ⇒ Boolean
8 9 10 |
# File 'lib/filament/os.rb', line 8 def windows? return cygwin? end |