Class: WindowsPath

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/windows_path.rb

Overview

Manages access to and updating of windows path setting.

Constant Summary collapse

FILE_SEPARATOR =
File::ALT_SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWindowsPath

Returns a new instance of WindowsPath.



67
68
69
70
71
# File 'lib/windows_path.rb', line 67

def initialize
  @system = WindowsPath.shell.Environment("System")
  @paths = WindowsPathArray.new
  @system.Item("Path").split(";").each { |p| @paths.add(p.strip) }
end

Instance Attribute Details

#pathsObject

paths is a WindowsPathArray holding all paths in the system.



50
51
52
# File 'lib/windows_path.rb', line 50

def paths
  @paths
end

Class Method Details

.expand_vars(path) ⇒ Object

Given a path, expands any environment variables found in it. Returns the expanded path.



59
60
61
62
63
64
65
# File 'lib/windows_path.rb', line 59

def self.expand_vars(path)
  while m = path.match(/%.*?%/)
    path = path.gsub(m[0], shell.ExpandEnvironmentStrings(m[0]))
  end

  path
end

.shellObject

Holds a reference to the Win32 Shell COM object.



53
54
55
# File 'lib/windows_path.rb', line 53

def self.shell
   @shell ||= WIN32OLE.new("WScript.Shell")
end

Instance Method Details

#updateObject

Update any changes



74
75
76
# File 'lib/windows_path.rb', line 74

def update
  @system["Item", "Path"] = @paths.join(";")
end