env 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -1
- data/.gitignore +2 -0
- data/ChangeLog.md +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/Rakefile +6 -6
- data/env.gemspec +103 -13
- data/gemspec.yml +3 -3
- data/lib/env/env.rb +2 -2
- data/lib/env/variables.rb +43 -15
- data/lib/env/version.rb +1 -1
- data/spec/variables_spec.rb +6 -6
- metadata +67 -56
data/.document
CHANGED
data/.gitignore
ADDED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 0.3.0 / 2012-05-27
|
2
|
+
|
3
|
+
* Added {Env::Variables#user}.
|
4
|
+
* Added {Env::Variables#host_name}.
|
5
|
+
* Fixed typos {Env.[]} and {Env.[]=} where the old `env_hash` method
|
6
|
+
was being called.
|
7
|
+
* Fixed specs that were stubbing the old `env_hash` method.
|
8
|
+
* Replaced ore-tasks with
|
9
|
+
[rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
|
10
|
+
|
1
11
|
### 0.2.0 / 2011-05-05
|
2
12
|
|
3
13
|
* Added {Env::Variables#timezone}.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Env
|
2
2
|
|
3
|
-
* [Homepage](
|
4
|
-
* [Issues](
|
3
|
+
* [Homepage](https://github.com/postmodern/env)
|
4
|
+
* [Issues](https://github.com/postmodern/env/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/env/frames)
|
6
6
|
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
7
|
|
@@ -79,6 +79,6 @@ Only access the common variables from your Class:
|
|
79
79
|
|
80
80
|
## Copyright
|
81
81
|
|
82
|
-
Copyright (c) 2011 Hal Brodigan
|
82
|
+
Copyright (c) 2011-2012 Hal Brodigan
|
83
83
|
|
84
84
|
See {file:LICENSE.txt} for details.
|
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
|
4
4
|
begin
|
5
|
-
gem '
|
6
|
-
require '
|
5
|
+
gem 'rubygems-tasks', '~> 0.1'
|
6
|
+
require 'rubygems/tasks'
|
7
7
|
|
8
|
-
|
8
|
+
Gem::Tasks.new
|
9
9
|
rescue LoadError => e
|
10
|
-
|
11
|
-
|
10
|
+
warn e.message
|
11
|
+
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
12
12
|
end
|
13
13
|
|
14
14
|
begin
|
@@ -25,7 +25,7 @@ task :test => :spec
|
|
25
25
|
task :default => :spec
|
26
26
|
|
27
27
|
begin
|
28
|
-
gem 'yard', '~> 0.
|
28
|
+
gem 'yard', '~> 0.7'
|
29
29
|
require 'yard'
|
30
30
|
|
31
31
|
YARD::Rake::YardocTask.new
|
data/env.gemspec
CHANGED
@@ -1,15 +1,105 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gemspec|
|
6
|
+
root = File.dirname(__FILE__)
|
7
|
+
lib_dir = File.join(root,'lib')
|
8
|
+
files = `git ls-files`.split($/)
|
9
|
+
|
10
|
+
filter_files = lambda { |paths|
|
11
|
+
files & case paths
|
12
|
+
when Array
|
13
|
+
paths
|
14
|
+
when String
|
15
|
+
Dir[paths]
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
19
|
+
version = {
|
20
|
+
:file => 'env/version',
|
21
|
+
:constant => 'Env::VERSION'
|
22
|
+
}
|
23
|
+
|
24
|
+
defaults = {
|
25
|
+
'name' => File.basename(root),
|
26
|
+
'files' => files,
|
27
|
+
'require_paths' => ['ext', 'lib'].select { |dir| File.directory?(dir) },
|
28
|
+
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
29
|
+
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
30
|
+
'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
31
|
+
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
|
32
|
+
}
|
33
|
+
|
34
|
+
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
35
|
+
|
36
|
+
gemspec.name = metadata['name']
|
37
|
+
gemspec.version = if metadata['version']
|
38
|
+
metadata['version']
|
39
|
+
else
|
40
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
41
|
+
|
42
|
+
require version[:file]
|
43
|
+
eval(version[:constant])
|
44
|
+
end
|
45
|
+
|
46
|
+
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
47
|
+
gemspec.description = metadata.fetch('description',metadata['summary'])
|
48
|
+
|
49
|
+
gemspec.licenses = Array(metadata['license'])
|
50
|
+
gemspec.authors = Array(metadata['authors'])
|
51
|
+
|
52
|
+
gemspec.email = metadata['email']
|
53
|
+
gemspec.homepage = metadata['homepage']
|
54
|
+
|
55
|
+
gemspec.require_paths = Array(metadata['require_paths'])
|
56
|
+
gemspec.files = filter_files[metadata['files']]
|
57
|
+
gemspec.files += Array(metadata['generated_files'])
|
58
|
+
gemspec.executables = metadata['executables']
|
59
|
+
gemspec.extensions = metadata['extensions']
|
60
|
+
|
61
|
+
if Gem::VERSION < '1.7.'
|
62
|
+
gemspec.default_executable = gemspec.executables.first
|
63
|
+
end
|
64
|
+
|
65
|
+
gemspec.test_files = filter_files[metadata['test_files']]
|
66
|
+
gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
|
67
|
+
|
68
|
+
gemspec.post_install_message = metadata['post_install_message']
|
69
|
+
gemspec.requirements = metadata['requirements']
|
70
|
+
|
71
|
+
if gemspec.respond_to?(:required_ruby_version=)
|
72
|
+
gemspec.required_ruby_version = metadata['required_ruby_version']
|
73
|
+
end
|
74
|
+
|
75
|
+
if gemspec.respond_to?(:required_rubygems_version=)
|
76
|
+
gemspec.required_rubygems_version = metadata['required_ruby_version']
|
77
|
+
end
|
78
|
+
|
79
|
+
parse_versions = lambda { |versions|
|
80
|
+
case versions
|
81
|
+
when Array
|
82
|
+
versions.map { |v| v.to_s }
|
83
|
+
when String
|
84
|
+
versions.split(/,\s*/)
|
85
|
+
end
|
86
|
+
}
|
87
|
+
|
88
|
+
if metadata['dependencies']
|
89
|
+
metadata['dependencies'].each do |name,versions|
|
90
|
+
gemspec.add_dependency(name,parse_versions[versions])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
if metadata['runtime_dependencies']
|
95
|
+
metadata['runtime_dependencies'].each do |name,versions|
|
96
|
+
gemspec.add_runtime_dependency(name,parse_versions[versions])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if metadata['development_dependencies']
|
101
|
+
metadata['development_dependencies'].each do |name,versions|
|
102
|
+
gemspec.add_development_dependency(name,parse_versions[versions])
|
103
|
+
end
|
14
104
|
end
|
15
105
|
end
|
data/gemspec.yml
CHANGED
@@ -7,10 +7,10 @@ description:
|
|
7
7
|
license: MIT
|
8
8
|
authors: Postmodern
|
9
9
|
email: postmodern.mod3@gmail.com
|
10
|
-
homepage:
|
10
|
+
homepage: https://github.com/postmodern/env#readme
|
11
11
|
has_yard: true
|
12
12
|
|
13
13
|
development_dependencies:
|
14
|
-
|
14
|
+
rubygems-tasks: ~> 0.1
|
15
15
|
rspec: ~> 2.4
|
16
|
-
yard: ~> 0.
|
16
|
+
yard: ~> 0.7
|
data/lib/env/env.rb
CHANGED
@@ -17,7 +17,7 @@ module Env
|
|
17
17
|
# # => "/bin/bash"
|
18
18
|
#
|
19
19
|
def Env.[](name)
|
20
|
-
|
20
|
+
env[name.to_s]
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -33,7 +33,7 @@ module Env
|
|
33
33
|
# The String value of the environment variable.
|
34
34
|
#
|
35
35
|
def Env.[]=(name,value)
|
36
|
-
|
36
|
+
env[name.to_s] = value.to_s
|
37
37
|
end
|
38
38
|
|
39
39
|
protected
|
data/lib/env/variables.rb
CHANGED
@@ -8,7 +8,9 @@ module Env
|
|
8
8
|
# @return [Hash{String => String}]
|
9
9
|
# The Hash of environment variable names and values.
|
10
10
|
#
|
11
|
-
|
11
|
+
# @api semipublic
|
12
|
+
#
|
13
|
+
def env
|
12
14
|
ENV
|
13
15
|
end
|
14
16
|
|
@@ -19,7 +21,7 @@ module Env
|
|
19
21
|
# The paths of the directories.
|
20
22
|
#
|
21
23
|
def paths
|
22
|
-
parse_paths(
|
24
|
+
parse_paths(env['PATH'])
|
23
25
|
end
|
24
26
|
|
25
27
|
#
|
@@ -29,7 +31,33 @@ module Env
|
|
29
31
|
# The paths of the directories.
|
30
32
|
#
|
31
33
|
def ld_library_paths
|
32
|
-
parse_paths(
|
34
|
+
parse_paths(env['LD_LIBRARY_PATH'])
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# The host-name of the system.
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
# The host-name.
|
42
|
+
#
|
43
|
+
# @since 0.3.0
|
44
|
+
#
|
45
|
+
def host_name
|
46
|
+
env['HOSTNAME']
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# The name of the current user.
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
# The name of the user.
|
54
|
+
#
|
55
|
+
# @since 0.3.0
|
56
|
+
#
|
57
|
+
def user
|
58
|
+
# USER is used on GNU/Linux and Windows
|
59
|
+
# LOGNAME is the POSIX user-name ENV variable
|
60
|
+
env['USER'] || env['LOGNAME']
|
33
61
|
end
|
34
62
|
|
35
63
|
#
|
@@ -40,10 +68,10 @@ module Env
|
|
40
68
|
#
|
41
69
|
def home
|
42
70
|
# logic adapted from Gem.find_home.
|
43
|
-
path = if (
|
44
|
-
|
45
|
-
elsif (
|
46
|
-
"#{
|
71
|
+
path = if (env['HOME'] || env['USERPROFILE'])
|
72
|
+
env['HOME'] || env['USERPROFILE']
|
73
|
+
elsif (env['HOMEDRIVE'] && env['HOMEPATH'])
|
74
|
+
"#{env['HOMEDRIVE']}#{env['HOMEPATH']}"
|
47
75
|
else
|
48
76
|
begin
|
49
77
|
File.expand_path('~')
|
@@ -66,7 +94,7 @@ module Env
|
|
66
94
|
# The language name and encoding.
|
67
95
|
#
|
68
96
|
def lang
|
69
|
-
if (lang =
|
97
|
+
if (lang = env['LANG'])
|
70
98
|
lang.split('.',2)
|
71
99
|
else
|
72
100
|
[]
|
@@ -92,7 +120,7 @@ module Env
|
|
92
120
|
# The number of columns.
|
93
121
|
#
|
94
122
|
def columns
|
95
|
-
|
123
|
+
env['COLUMNS'].to_i if env['COLUMNS']
|
96
124
|
end
|
97
125
|
|
98
126
|
#
|
@@ -102,7 +130,7 @@ module Env
|
|
102
130
|
# The number of lines.
|
103
131
|
#
|
104
132
|
def lines
|
105
|
-
|
133
|
+
env['LINES'].to_i if env['LINES']
|
106
134
|
end
|
107
135
|
|
108
136
|
#
|
@@ -112,7 +140,7 @@ module Env
|
|
112
140
|
# The path to the default shell.
|
113
141
|
#
|
114
142
|
def shell
|
115
|
-
|
143
|
+
env['SHELL']
|
116
144
|
end
|
117
145
|
|
118
146
|
#
|
@@ -132,7 +160,7 @@ module Env
|
|
132
160
|
# The name of the terminal program.
|
133
161
|
#
|
134
162
|
def terminal
|
135
|
-
|
163
|
+
env['COLORTERM'] || env['TERM']
|
136
164
|
end
|
137
165
|
|
138
166
|
#
|
@@ -142,7 +170,7 @@ module Env
|
|
142
170
|
# The name of the editor program.
|
143
171
|
#
|
144
172
|
def editor
|
145
|
-
|
173
|
+
env['EDITOR']
|
146
174
|
end
|
147
175
|
|
148
176
|
#
|
@@ -152,7 +180,7 @@ module Env
|
|
152
180
|
# The name of the browser program.
|
153
181
|
#
|
154
182
|
def browser
|
155
|
-
|
183
|
+
env['BROWSER']
|
156
184
|
end
|
157
185
|
|
158
186
|
#
|
@@ -164,7 +192,7 @@ module Env
|
|
164
192
|
# @since 0.2.0
|
165
193
|
#
|
166
194
|
def debug?
|
167
|
-
true if
|
195
|
+
true if env['DEBUG']
|
168
196
|
end
|
169
197
|
|
170
198
|
protected
|
data/lib/env/version.rb
CHANGED
data/spec/variables_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Variables do
|
|
9
9
|
let(:shell) { '/bin/bash' }
|
10
10
|
|
11
11
|
before(:each) do
|
12
|
-
subject.stub!(:
|
12
|
+
subject.stub!(:env).and_return(
|
13
13
|
'PATH' => '/usr/local/bin:/usr/bin:/bin',
|
14
14
|
'HOME' => home,
|
15
15
|
'TERM' => term,
|
@@ -34,7 +34,7 @@ describe Variables do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should use the USERPROFILE variable if HOME is not set" do
|
37
|
-
subject.stub!(:
|
37
|
+
subject.stub!(:env).and_return('USERPROFILE' => home)
|
38
38
|
|
39
39
|
subject.home.should == Pathname.new(home)
|
40
40
|
end
|
@@ -42,7 +42,7 @@ describe Variables do
|
|
42
42
|
it "should use HOMEDRIVE and HOMEPATH if HOME is not set" do
|
43
43
|
drive = 'C:'
|
44
44
|
|
45
|
-
subject.stub!(:
|
45
|
+
subject.stub!(:env).and_return(
|
46
46
|
'HOMEDRIVE' => drive,
|
47
47
|
'HOMEPATH' => home
|
48
48
|
)
|
@@ -51,7 +51,7 @@ describe Variables do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should attempt to expand '~' if none of the HOME variables are set" do
|
54
|
-
subject.stub!(:
|
54
|
+
subject.stub!(:env).and_return({})
|
55
55
|
|
56
56
|
subject.home.should be_directory
|
57
57
|
end
|
@@ -64,7 +64,7 @@ describe Variables do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should return an empty Array if LANG is not set" do
|
67
|
-
subject.stub!(:
|
67
|
+
subject.stub!(:env).and_return({})
|
68
68
|
|
69
69
|
subject.lang.should be_empty
|
70
70
|
end
|
@@ -90,7 +90,7 @@ describe Variables do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should check COLORTERM before the TERM variable" do
|
93
|
-
subject.stub!(:
|
93
|
+
subject.stub!(:env).and_return(
|
94
94
|
'COLORTERM' => 'gnome-terminal',
|
95
95
|
'TERM' => term
|
96
96
|
)
|
metadata
CHANGED
@@ -1,64 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: env
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Postmodern
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
prerelease: false
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubygems-tasks
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.1'
|
24
22
|
type: :development
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: rspec
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
30
33
|
none: false
|
31
|
-
requirements:
|
34
|
+
requirements:
|
32
35
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.4'
|
35
38
|
type: :development
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: yard
|
39
39
|
prerelease: false
|
40
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
41
49
|
none: false
|
42
|
-
requirements:
|
50
|
+
requirements:
|
43
51
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.7'
|
46
54
|
type: :development
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
description: Provides a Ruby interface to common environment variables, used on Windows,
|
63
|
+
Linux, BSD and OSX.
|
64
|
+
email: postmodern.mod3@gmail.com
|
51
65
|
executables: []
|
52
|
-
|
53
66
|
extensions: []
|
54
|
-
|
55
|
-
extra_rdoc_files:
|
56
|
-
- README.md
|
67
|
+
extra_rdoc_files:
|
57
68
|
- ChangeLog.md
|
58
69
|
- LICENSE.txt
|
59
|
-
|
70
|
+
- README.md
|
71
|
+
files:
|
60
72
|
- .document
|
61
73
|
- .gemtest
|
74
|
+
- .gitignore
|
62
75
|
- .rspec
|
63
76
|
- .yardopts
|
64
77
|
- ChangeLog.md
|
@@ -74,33 +87,31 @@ files:
|
|
74
87
|
- spec/env_spec.rb
|
75
88
|
- spec/spec_helper.rb
|
76
89
|
- spec/variables_spec.rb
|
77
|
-
homepage:
|
78
|
-
licenses:
|
90
|
+
homepage: https://github.com/postmodern/env#readme
|
91
|
+
licenses:
|
79
92
|
- MIT
|
80
93
|
post_install_message:
|
81
94
|
rdoc_options: []
|
82
|
-
|
83
|
-
require_paths:
|
95
|
+
require_paths:
|
84
96
|
- lib
|
85
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
98
|
none: false
|
87
|
-
requirements:
|
88
|
-
- -
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version:
|
91
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
104
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version:
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
97
109
|
requirements: []
|
98
|
-
|
99
|
-
|
100
|
-
rubygems_version: 1.8.0
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.8.24
|
101
112
|
signing_key:
|
102
113
|
specification_version: 3
|
103
114
|
summary: Provides a Ruby interface to common environment variables
|
104
|
-
test_files:
|
105
|
-
- spec/variables_spec.rb
|
115
|
+
test_files:
|
106
116
|
- spec/env_spec.rb
|
117
|
+
- spec/variables_spec.rb
|