win-path-utils 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02c116e701ee6f656b4bf6ffb6d080af3f6f63a5
4
- data.tar.gz: 0742e5b289decafb9997a7d96b2cdab3ae24b2d7
3
+ metadata.gz: 6469652ca4cb953ba2594393916bd16e1667a7db
4
+ data.tar.gz: 7c733a564ce1291c96e827fc2e01c3d4204db71a
5
5
  SHA512:
6
- metadata.gz: de0d7916cc04a6d42ae72f5a537cc085d4eb141a6416922ca3afa7330ae2df5bf8b58f110dd1f68a5324b770e8ce4a73b3d50b9eedc045bbcf19682c802f6a3d
7
- data.tar.gz: 6200874b47c1a1d0f422cb8d233959677a0b49ddad736eb3dab8e36bfba12ca803b35faaa12c4ddb16f28bcfd1e55632c9cd862862c2bca1c6d4789793c9d6d1
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
@@ -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"
@@ -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
- def initialize(options = {})
10
- @separator = options[:separator] || ';'
11
-
12
- options[:type] ||= :system
13
-
14
- @hkey, @reg_path, @key_name = case options[:type]
15
- when :system
16
- [Win32::Registry::HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path']
17
- when :local, :user
18
- [Win32::Registry::HKEY_CURRENT_USER, 'Environment', 'PATH']
19
- else
20
- raise WrongOptionError, "Unknown type!"
21
- end
22
-
23
- @hkey = options[:hkey] if options.key?(:hkey)
24
- @reg_path = options[:reg_path] if options.key?(:reg_path)
25
- @key_name = options[:key_name] if options.key?(:key_name)
26
- end
27
-
28
- # Sets the entire PATH variable to provided string
29
- def set(value)
30
- with_reg do |reg|
31
- reg[@key_name] = value
32
- end
33
- end
34
-
35
- # Returns the entire PATH variable as string
36
- def get
37
- with_reg do |reg|
38
- begin
39
- reg.read(@key_name)[1]
40
- rescue Win32::Registry::Error
41
- nil
42
- end
43
- end
44
- end
45
-
46
- # Sets the entire PATH variable to provided array
47
- # Joins with @separator
48
- def set_array(value)
49
- set(value.join(@separator))
50
- end
51
-
52
- # Returns the entire PATH variable as array
53
- # Splits with @separator
54
- def get_array
55
- get.split(@separator)
56
- end
57
-
58
- # Adds value to the path
59
- def add(value, options = {})
60
- # Set defaults
61
- options[:duplication_filter] = :do_not_add unless options.key?(:duplication_filter)
62
-
63
- # Get path
64
- path = get_array
65
-
66
- # Check duplicates
67
- if path.member?(value)
68
- case options[:duplication_filter]
69
- when :do_not_add, :deny
70
- # do nothing, we already have one in the list
71
- return
72
- when :remove_existing
73
- path.delete!(value)
74
- when :none
75
- # just pass through
76
- else
77
- raise WrongOptionError, "Unknown :duplication_filter!"
78
- end
79
- end
80
-
81
- # Change path array
82
- case options[:where]
83
- when :start, :left
84
- path.unshift value
85
- when :end, :right
86
- path.push value
87
- else
88
- raise WrongOptionError, "Unknown :where!"
89
- end
90
-
91
- # Save new array
92
- set_array(path)
93
- end
94
-
95
- # Adds element to the end of the path if not exists
96
- def push(value, options = {})
97
- add(value, options.merge(where: :end))
98
- end
99
- alias_method :append, :push
100
-
101
- # Adds element to the start of the path if not exists
102
- def unshift(value, options = {})
103
- add(value, options.merge(where: :start))
104
- end
105
- alias_method :prepend, :unshift
106
-
107
- # Removes the item from the path
108
- def remove(value)
109
- path = get_array
110
- path.delete(value)
111
- set_array(path)
112
- end
113
- alias_method :delete, :remove
114
-
115
- # Checks the inclusion of value in path
116
- def include?(value)
117
- get_array.include?(value)
118
- end
119
- alias_method :member?, :include?
120
-
121
- private
122
-
123
- # Execute block with the current reg settings
124
- def with_reg(access_mask = Win32::Registry::Constants::KEY_ALL_ACCESS, &block)
125
- @hkey.open(@reg_path, access_mask, &block)
126
- end
127
- end
128
- end
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.1.0"
3
- end
1
+ module WinPathUtils
2
+ VERSION = "0.2.0"
3
+ end
@@ -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.1.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: 2013-11-23 00:00:00.000000000 Z
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.1.10
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