Class: WindowsPath
Overview
Manages access to and updating of windows path setting.
Constant Summary collapse
- FILE_SEPARATOR =
File::ALT_SEPARATOR
Instance Attribute Summary collapse
-
#paths ⇒ Object
paths is a WindowsPathArray holding all paths in the system.
Class Method Summary collapse
-
.expand_vars(path) ⇒ Object
Given a path, expands any environment variables found in it.
-
.shell ⇒ Object
Holds a reference to the Win32 Shell COM object.
Instance Method Summary collapse
-
#initialize ⇒ WindowsPath
constructor
A new instance of WindowsPath.
-
#update ⇒ Object
Update any changes.
Constructor Details
#initialize ⇒ WindowsPath
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
#paths ⇒ Object
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.(path) while m = path.match(/%.*?%/) path = path.gsub(m[0], shell.ExpandEnvironmentStrings(m[0])) end path end |
.shell ⇒ Object
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
#update ⇒ Object
Update any changes
74 75 76 |
# File 'lib/windows_path.rb', line 74 def update @system["Item", "Path"] = @paths.join(";") end |