Module: Filament::OS

Defined in:
lib/filament/os.rb

Instance Method Summary collapse

Instance Method Details

#cygwin?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/filament/os.rb', line 10

def cygwin?
  return ! PLATFORM.index("cygwin").nil?
end

#darwin?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/filament/os.rb', line 2

def darwin?
 return ! PLATFORM.index("darwin").nil?
end

#fix_paths(paths) ⇒ Object Also known as: fix



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/filament/os.rb', line 48

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



60
61
62
63
64
65
66
67
68
69
# File 'lib/filament/os.rb', line 60

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



14
15
16
17
# File 'lib/filament/os.rb', line 14

def sys(c)
  log c
  raise "!!! Error executing '#{c}'" unless system(c)
end

#to_exec_path(path) ⇒ Object



30
31
32
33
34
# File 'lib/filament/os.rb', line 30

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



19
20
21
22
23
24
25
26
27
28
# File 'lib/filament/os.rb', line 19

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



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/filament/os.rb', line 36

def to_windows_path(path)
  return nil if path.nil?
  if path.index('cygdrive').nil?
    return path
  end

  path = path.chomp.sub(/\/cygdrive\//, '')
  drive, path = path.split(/\//, 2)

  return "#{drive}:/#{path}"
end

#windows?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/filament/os.rb', line 6

def windows?
  return cygwin?
end