env 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ ### 0.1.2 / 2011-01-23
2
+
3
+ * Fixed {Env::Variables#home} to match the behavior of `Gem.find_home`.
4
+ * Have {Env::Variables#lang} return an empty Array if the `LANG`
5
+ environment variable is not set.
6
+
1
7
  ### 0.1.0 / 2011-01-22
2
8
 
3
9
  * Initial release:
@@ -35,13 +35,28 @@ module Env
35
35
  #
36
36
  # The home directory.
37
37
  #
38
- # @return [Pathname, nil]
38
+ # @return [Pathname]
39
39
  # The path of the home directory.
40
40
  #
41
41
  def home
42
- if (home = (env_hash['HOME'] || env_hash['HOMEPATH']))
43
- Pathname.new(home)
44
- end
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'].split('.',2)
69
+ if (lang = env_hash['LANG'])
70
+ lang.split('.',2)
71
+ else
72
+ []
73
+ end
55
74
  end
56
75
 
57
76
  #
@@ -1,4 +1,4 @@
1
1
  module Env
2
2
  # env version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -32,12 +32,29 @@ describe Variables do
32
32
  subject.home.should == Pathname.new(home)
33
33
  end
34
34
 
35
- it "should check HOMEPATH if HOME is not set" do
36
- subject.stub!(:env_hash).and_return('HOMEPATH' => home)
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
- - 0
9
- version: 0.1.0
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-22 00:00:00 -08:00
17
+ date: 2011-01-23 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency