ruby-nuggets 0.5.1 → 0.5.2
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.
- data/README +1 -1
- data/lib/nuggets/env/set.rb +3 -0
- data/lib/nuggets/env/set_mixin.rb +68 -0
- data/lib/nuggets/env/user_encoding.rb +2 -52
- data/lib/nuggets/env/user_encoding_mixin.rb +55 -0
- data/lib/nuggets/env/user_home.rb +2 -53
- data/lib/nuggets/env/user_home_mixin.rb +55 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +9 -5
data/README
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2008-2009 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
module Nuggets
|
29
|
+
module Env
|
30
|
+
module SetMixin
|
31
|
+
|
32
|
+
# call-seq:
|
33
|
+
# ENV.set(env = {}, clear = true) => aHash
|
34
|
+
# ENV.set(env = {}, clear = true) { ... } => anObject
|
35
|
+
#
|
36
|
+
# Overrides ENV with +env+, clearing it beforehand if +clear+ is true. If a
|
37
|
+
# block is given, restores ENV to its original state afterwards and returns
|
38
|
+
# the result of the block; otherwise returns the original ENV as a hash.
|
39
|
+
def set(env = {}, clear = true)
|
40
|
+
old_env = to_hash
|
41
|
+
|
42
|
+
self.clear if clear
|
43
|
+
|
44
|
+
env.each { |key, value|
|
45
|
+
key = key.to_s.upcase unless key.is_a?(String)
|
46
|
+
value = value.to_s unless value.is_a?(String)
|
47
|
+
|
48
|
+
self[key] = value
|
49
|
+
}
|
50
|
+
|
51
|
+
block_given? ? yield : old_env
|
52
|
+
ensure
|
53
|
+
set(old_env) if old_env && block_given?
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :without, :set
|
57
|
+
|
58
|
+
# call-seq:
|
59
|
+
# ENV.with(env = {}, clear = false) { ... } => anObject
|
60
|
+
#
|
61
|
+
# Temporarily overrides ENV with +env+ for the block execution. See #set.
|
62
|
+
def with(env = {}, clear = false)
|
63
|
+
set(env, clear) { yield }
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,53 +1,3 @@
|
|
1
|
-
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2008 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU General Public License as published by the Free #
|
14
|
-
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
-
# any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
-
# more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU General Public License along #
|
23
|
-
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
1
|
+
require 'nuggets/env/user_encoding_mixin'
|
27
2
|
|
28
|
-
|
29
|
-
require 'win32console'
|
30
|
-
rescue LoadError
|
31
|
-
end
|
32
|
-
|
33
|
-
class << ENV
|
34
|
-
|
35
|
-
# call-seq:
|
36
|
-
# ENV.user_encoding => aString or nil
|
37
|
-
#
|
38
|
-
# Finds the user's selected encoding.
|
39
|
-
def user_encoding
|
40
|
-
ENV['ENCODING'] ||
|
41
|
-
ENV['LANG'][/\.(.*)/, 1] ||
|
42
|
-
if defined?(Win32::Console)
|
43
|
-
"CP#{Win32::Console.InputCP}"
|
44
|
-
else
|
45
|
-
cp = %x{chcp}[/:\s*(.*?)\./, 1] and "CP#{cp}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
if $0 == __FILE__
|
52
|
-
p ENV.user_encoding
|
53
|
-
end
|
3
|
+
ENV.extend(Nuggets::Env::UserEncodingMixin)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2008-2009 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'win32console'
|
30
|
+
rescue LoadError
|
31
|
+
end
|
32
|
+
|
33
|
+
module Nuggets
|
34
|
+
module Env
|
35
|
+
module UserEncodingMixin
|
36
|
+
|
37
|
+
# call-seq:
|
38
|
+
# ENV.user_encoding => aString
|
39
|
+
#
|
40
|
+
# Finds the user's selected encoding.
|
41
|
+
def user_encoding(default = 'UTF-8')
|
42
|
+
self['ENCODING'] || begin
|
43
|
+
lang = self['LANG']
|
44
|
+
lang[/\.(.*)/, 1] if lang
|
45
|
+
end || if defined?(Win32::Console)
|
46
|
+
"CP#{Win32::Console.InputCP}"
|
47
|
+
elsif ::File::ALT_SEPARATOR
|
48
|
+
cp = %x{chcp}[/:\s*(.*?)\./, 1]
|
49
|
+
"CP#{cp}" if cp
|
50
|
+
end || default
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,54 +1,3 @@
|
|
1
|
-
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2008 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU General Public License as published by the Free #
|
14
|
-
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
-
# any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
-
# more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU General Public License along #
|
23
|
-
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
1
|
+
require 'nuggets/env/user_home_mixin'
|
27
2
|
|
28
|
-
|
29
|
-
|
30
|
-
# call-seq:
|
31
|
-
# ENV.user_home => aString
|
32
|
-
#
|
33
|
-
# Finds the user's home directory. Stolen from RubyGems ;-)
|
34
|
-
def user_home
|
35
|
-
%w[HOME USERPROFILE].each { |homekey|
|
36
|
-
return ENV[homekey] if ENV[homekey]
|
37
|
-
}
|
38
|
-
|
39
|
-
if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
|
40
|
-
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
|
41
|
-
end
|
42
|
-
|
43
|
-
begin
|
44
|
-
File.expand_path('~')
|
45
|
-
rescue ArgumentError
|
46
|
-
File::ALT_SEPARATOR ? 'C:/' : '/'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
if $0 == __FILE__
|
53
|
-
p ENV.user_home
|
54
|
-
end
|
3
|
+
ENV.extend(Nuggets::Env::UserHomeMixin)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2008-2009 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
module Nuggets
|
29
|
+
module Env
|
30
|
+
module UserHomeMixin
|
31
|
+
|
32
|
+
# call-seq:
|
33
|
+
# ENV.user_home => aString
|
34
|
+
#
|
35
|
+
# Finds the user's home directory. Stolen from RubyGems ;-)
|
36
|
+
def user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/')
|
37
|
+
%w[HOME USERPROFILE].each { |homekey|
|
38
|
+
home = self[homekey]
|
39
|
+
return home if home
|
40
|
+
}
|
41
|
+
|
42
|
+
if drive = self['HOMEDRIVE'] and path = self['HOMEPATH']
|
43
|
+
return "#{drive}:#{path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
::File.expand_path('~')
|
48
|
+
rescue ArgumentError
|
49
|
+
default
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-12 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,7 +25,11 @@ extra_rdoc_files:
|
|
25
25
|
- README
|
26
26
|
files:
|
27
27
|
- lib/nuggets/env/user_home.rb
|
28
|
+
- lib/nuggets/env/user_home_mixin.rb
|
28
29
|
- lib/nuggets/env/user_encoding.rb
|
30
|
+
- lib/nuggets/env/set_mixin.rb
|
31
|
+
- lib/nuggets/env/user_encoding_mixin.rb
|
32
|
+
- lib/nuggets/env/set.rb
|
29
33
|
- lib/nuggets/numeric/limit.rb
|
30
34
|
- lib/nuggets/numeric/to_multiple.rb
|
31
35
|
- lib/nuggets/numeric/between.rb
|
@@ -102,15 +106,15 @@ has_rdoc: true
|
|
102
106
|
homepage: http://prometheus.rubyforge.org/ruby-nuggets
|
103
107
|
post_install_message:
|
104
108
|
rdoc_options:
|
109
|
+
- --main
|
110
|
+
- README
|
105
111
|
- --line-numbers
|
106
112
|
- --inline-source
|
107
113
|
- --title
|
108
114
|
- ruby-nuggets Application documentation
|
109
|
-
- --
|
110
|
-
- README
|
115
|
+
- --all
|
111
116
|
- --charset
|
112
117
|
- UTF-8
|
113
|
-
- --all
|
114
118
|
require_paths:
|
115
119
|
- lib
|
116
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|