win-path-utils 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +51 -51
- data/Rakefile +1 -1
- data/lib/win-path-utils.rb +148 -128
- data/lib/win-path-utils/version.rb +3 -3
- data/win-path-utils.gemspec +23 -23
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6469652ca4cb953ba2594393916bd16e1667a7db
|
4
|
+
data.tar.gz: 7c733a564ce1291c96e827fc2e01c3d4204db71a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9175bc148fbc6e17f48b8d873953a162ba45e1fbea9f7be4ec5b0d26dec8d85943860793a9a31ac9e601b708489d18f2a3244920e8486d94659eb90ef822c45
|
7
|
+
data.tar.gz: ebc3a7663aec3c46c7fe564a0f7426cc9bf5204ea6d9d28d51a72ba27fe3db8da4cd7f858a6e6086820e2bdfcc5a3be29a41fc6afc457d53a70709bbb0bf8484
|
data/.gitignore
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in win-path-utils.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in win-path-utils.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2013 MOZGIII
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2013 MOZGIII
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
# WinPathUtils
|
2
|
-
|
3
|
-
This gem allows you to manupulate Windows' system `PATH` variable via registry.
|
4
|
-
It provides convenient methods to add and remove items to `PATH`.
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
gem 'win-path-utils'
|
11
|
-
|
12
|
-
And then execute:
|
13
|
-
|
14
|
-
$ bundle
|
15
|
-
|
16
|
-
Or install it yourself as:
|
17
|
-
|
18
|
-
$ gem install win-path-utils
|
19
|
-
|
20
|
-
## Usage
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
require 'win-path-utils'
|
24
|
-
|
25
|
-
path = WinPathUtils::Path.new
|
26
|
-
|
27
|
-
# Get the PATH
|
28
|
-
path_value = path.get # => "C:\Ruby\bin;C:\..."
|
29
|
-
|
30
|
-
# Append something
|
31
|
-
path.append('C:\test\at\the\end')
|
32
|
-
|
33
|
-
# Prepend something
|
34
|
-
path.prepend('C:\test\at\the\beginning')
|
35
|
-
|
36
|
-
# Get the PATH now - it's updated
|
37
|
-
new_path_value = path.get # => "C:\test\at\the\beginning;C:\Ruby\bin;C:\..."
|
38
|
-
|
39
|
-
# Remove something
|
40
|
-
path.remove('C:\test')
|
41
|
-
```
|
42
|
-
|
43
|
-
Just read the code, it's pretty straightforward.
|
44
|
-
|
45
|
-
## Contributing
|
46
|
-
|
47
|
-
1. Fork it
|
48
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
-
5. Create new Pull Request
|
1
|
+
# WinPathUtils
|
2
|
+
|
3
|
+
This gem allows you to manupulate Windows' system `PATH` variable via registry.
|
4
|
+
It provides convenient methods to add and remove items to `PATH`.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'win-path-utils'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install win-path-utils
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'win-path-utils'
|
24
|
+
|
25
|
+
path = WinPathUtils::Path.new
|
26
|
+
|
27
|
+
# Get the PATH
|
28
|
+
path_value = path.get # => "C:\Ruby\bin;C:\..."
|
29
|
+
|
30
|
+
# Append something
|
31
|
+
path.append('C:\test\at\the\end')
|
32
|
+
|
33
|
+
# Prepend something
|
34
|
+
path.prepend('C:\test\at\the\beginning')
|
35
|
+
|
36
|
+
# Get the PATH now - it's updated
|
37
|
+
new_path_value = path.get # => "C:\test\at\the\beginning;C:\Ruby\bin;C:\..."
|
38
|
+
|
39
|
+
# Remove something
|
40
|
+
path.remove('C:\test')
|
41
|
+
```
|
42
|
+
|
43
|
+
Just read the code, it's pretty straightforward.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/win-path-utils.rb
CHANGED
@@ -1,128 +1,148 @@
|
|
1
|
-
require "win-path-utils/version"
|
2
|
-
|
3
|
-
require "win32/registry"
|
4
|
-
|
5
|
-
module WinPathUtils
|
6
|
-
class Path
|
7
|
-
class WrongOptionError < StandardError; end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
path
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
1
|
+
require "win-path-utils/version"
|
2
|
+
|
3
|
+
require "win32/registry"
|
4
|
+
|
5
|
+
module WinPathUtils
|
6
|
+
class Path
|
7
|
+
class WrongOptionError < StandardError; end
|
8
|
+
class SetxError < StandardError; end
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@separator = options[:separator] || ';'
|
12
|
+
|
13
|
+
options[:type] ||= :system
|
14
|
+
|
15
|
+
@hkey, @reg_path, @key_name = case options[:type]
|
16
|
+
when :system
|
17
|
+
[Win32::Registry::HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path']
|
18
|
+
when :local, :user
|
19
|
+
[Win32::Registry::HKEY_CURRENT_USER, 'Environment', 'PATH']
|
20
|
+
else
|
21
|
+
raise WrongOptionError, "Unknown type!"
|
22
|
+
end
|
23
|
+
|
24
|
+
@hkey = options[:hkey] if options.key?(:hkey)
|
25
|
+
@reg_path = options[:reg_path] if options.key?(:reg_path)
|
26
|
+
@key_name = options[:key_name] if options.key?(:key_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Sets the entire PATH variable to provided string
|
30
|
+
def set(value)
|
31
|
+
with_reg do |reg|
|
32
|
+
reg[@key_name] = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the entire PATH variable as string
|
37
|
+
def get
|
38
|
+
with_reg do |reg|
|
39
|
+
begin
|
40
|
+
reg.read(@key_name)[1]
|
41
|
+
rescue Win32::Registry::Error
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sets the entire PATH variable to provided array
|
48
|
+
# Joins with @separator
|
49
|
+
def set_array(value)
|
50
|
+
set(value.join(@separator))
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the entire PATH variable as array
|
54
|
+
# Splits with @separator
|
55
|
+
def get_array
|
56
|
+
get.split(@separator)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Adds value to the path
|
60
|
+
def add(value, options = {})
|
61
|
+
# Set defaults
|
62
|
+
options[:duplication_filter] = :do_not_add unless options.key?(:duplication_filter)
|
63
|
+
|
64
|
+
# Get path
|
65
|
+
path = get_array
|
66
|
+
|
67
|
+
# Check duplicates
|
68
|
+
if path.member?(value)
|
69
|
+
case options[:duplication_filter]
|
70
|
+
when :do_not_add, :deny
|
71
|
+
# do nothing, we already have one in the list
|
72
|
+
return
|
73
|
+
when :remove_existing
|
74
|
+
path.delete!(value)
|
75
|
+
when :none
|
76
|
+
# just pass through
|
77
|
+
else
|
78
|
+
raise WrongOptionError, "Unknown :duplication_filter!"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Change path array
|
83
|
+
case options[:where]
|
84
|
+
when :start, :left
|
85
|
+
path.unshift value
|
86
|
+
when :end, :right
|
87
|
+
path.push value
|
88
|
+
else
|
89
|
+
raise WrongOptionError, "Unknown :where!"
|
90
|
+
end
|
91
|
+
|
92
|
+
# Save new array
|
93
|
+
set_array(path)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Adds element to the end of the path if not exists
|
97
|
+
def push(value, options = {})
|
98
|
+
add(value, options.merge(where: :end))
|
99
|
+
end
|
100
|
+
alias_method :append, :push
|
101
|
+
|
102
|
+
# Adds element to the start of the path if not exists
|
103
|
+
def unshift(value, options = {})
|
104
|
+
add(value, options.merge(where: :start))
|
105
|
+
end
|
106
|
+
alias_method :prepend, :unshift
|
107
|
+
|
108
|
+
# Removes the item from the path
|
109
|
+
def remove(value)
|
110
|
+
path = get_array
|
111
|
+
path.delete(value)
|
112
|
+
set_array(path)
|
113
|
+
end
|
114
|
+
alias_method :delete, :remove
|
115
|
+
|
116
|
+
# Checks the inclusion of value in path
|
117
|
+
def include?(value)
|
118
|
+
get_array.include?(value)
|
119
|
+
end
|
120
|
+
alias_method :member?, :include?
|
121
|
+
|
122
|
+
# Cause Windows to reload environment from registry
|
123
|
+
def self.commit!
|
124
|
+
var = "WIN_PATH_UTILS_TMPVAR"
|
125
|
+
|
126
|
+
fd_r, fd_w = IO.pipe
|
127
|
+
result = system("setx", var, "", [:out, :err] => fd_w)
|
128
|
+
fd_w.close
|
129
|
+
output = fd_r.read
|
130
|
+
|
131
|
+
raise SetxError.new("SETX error: #{output}") if result == false
|
132
|
+
|
133
|
+
result
|
134
|
+
end
|
135
|
+
|
136
|
+
# Alias
|
137
|
+
def commit!
|
138
|
+
self.class.commit!
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
# Execute block with the current reg settings
|
144
|
+
def with_reg(access_mask = Win32::Registry::Constants::KEY_ALL_ACCESS, &block)
|
145
|
+
@hkey.open(@reg_path, access_mask, &block)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module WinPathUtils
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module WinPathUtils
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
data/win-path-utils.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'win-path-utils/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "win-path-utils"
|
8
|
-
spec.version = WinPathUtils::VERSION
|
9
|
-
spec.authors = ["MOZGIII"]
|
10
|
-
spec.email = ["mike-n@narod.ru"]
|
11
|
-
spec.description = %q{Provides an API to add and remove values from Windows' system PATH variable}
|
12
|
-
spec.summary = %q{Provides an API to add and remove values from Windows' system PATH variable}
|
13
|
-
spec.homepage = "https://github.com/MOZGIII/win-path-utils"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'win-path-utils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "win-path-utils"
|
8
|
+
spec.version = WinPathUtils::VERSION
|
9
|
+
spec.authors = ["MOZGIII"]
|
10
|
+
spec.email = ["mike-n@narod.ru"]
|
11
|
+
spec.description = %q{Provides an API to add and remove values from Windows' system PATH variable}
|
12
|
+
spec.summary = %q{Provides an API to add and remove values from Windows' system PATH variable}
|
13
|
+
spec.homepage = "https://github.com/MOZGIII/win-path-utils"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win-path-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MOZGIII
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
77
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.0.3
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Provides an API to add and remove values from Windows' system PATH variable
|