env 0.1.0 → 0.1.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/ChangeLog.md +6 -0
- data/lib/env/variables.rb +24 -5
- data/lib/env/version.rb +1 -1
- data/spec/variables_spec.rb +25 -2
- metadata +3 -3
data/ChangeLog.md
CHANGED
data/lib/env/variables.rb
CHANGED
@@ -35,13 +35,28 @@ module Env
|
|
35
35
|
#
|
36
36
|
# The home directory.
|
37
37
|
#
|
38
|
-
# @return [Pathname
|
38
|
+
# @return [Pathname]
|
39
39
|
# The path of the home directory.
|
40
40
|
#
|
41
41
|
def home
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
# logic adapted from Gem.find_home.
|
43
|
+
path = if (env_hash['HOME'] || env_hash['USERPROFILE'])
|
44
|
+
env_hash['HOME'] || env_hash['USERPROFILE']
|
45
|
+
elsif (env_hash['HOMEDRIVE'] && env_hash['HOMEPATH'])
|
46
|
+
"#{env_hash['HOMEDRIVE']}#{env_hash['HOMEPATH']}"
|
47
|
+
else
|
48
|
+
begin
|
49
|
+
File.expand_path('~')
|
50
|
+
rescue
|
51
|
+
if File::ALT_SEPARATOR
|
52
|
+
'C:/'
|
53
|
+
else
|
54
|
+
'/'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
return Pathname.new(path)
|
45
60
|
end
|
46
61
|
|
47
62
|
#
|
@@ -51,7 +66,11 @@ module Env
|
|
51
66
|
# The language name and encoding.
|
52
67
|
#
|
53
68
|
def lang
|
54
|
-
env_hash['LANG']
|
69
|
+
if (lang = env_hash['LANG'])
|
70
|
+
lang.split('.',2)
|
71
|
+
else
|
72
|
+
[]
|
73
|
+
end
|
55
74
|
end
|
56
75
|
|
57
76
|
#
|
data/lib/env/version.rb
CHANGED
data/spec/variables_spec.rb
CHANGED
@@ -32,12 +32,29 @@ describe Variables do
|
|
32
32
|
subject.home.should == Pathname.new(home)
|
33
33
|
end
|
34
34
|
|
35
|
-
it "should
|
36
|
-
subject.stub!(:env_hash).and_return('
|
35
|
+
it "should use the USERPROFILE variable if HOME is not set" do
|
36
|
+
subject.stub!(:env_hash).and_return('USERPROFILE' => home)
|
37
37
|
|
38
38
|
subject.home.should == Pathname.new(home)
|
39
39
|
end
|
40
40
|
|
41
|
+
it "should use HOMEDRIVE and HOMEPATH if HOME is not set" do
|
42
|
+
drive = 'C:'
|
43
|
+
|
44
|
+
subject.stub!(:env_hash).and_return(
|
45
|
+
'HOMEDRIVE' => drive,
|
46
|
+
'HOMEPATH' => home
|
47
|
+
)
|
48
|
+
|
49
|
+
subject.home.should == Pathname.new(drive + home)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should attempt to expand '~' if none of the HOME variables are set" do
|
53
|
+
subject.stub!(:env_hash).and_return({})
|
54
|
+
|
55
|
+
subject.home.should be_directory
|
56
|
+
end
|
57
|
+
|
41
58
|
it "should parse the LANG variable" do
|
42
59
|
name, encoding = subject.lang
|
43
60
|
|
@@ -45,6 +62,12 @@ describe Variables do
|
|
45
62
|
encoding.should == 'UTF8'
|
46
63
|
end
|
47
64
|
|
65
|
+
it "should return an empty Array if LANG is not set" do
|
66
|
+
subject.stub!(:env_hash).and_return({})
|
67
|
+
|
68
|
+
subject.lang.should be_empty
|
69
|
+
end
|
70
|
+
|
48
71
|
it "should parse the COLUMNS variable" do
|
49
72
|
subject.columns.should == 80
|
50
73
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Postmodern
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-23 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|