environment 0.1.2 → 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.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +15 -2
- data/Rakefile +1 -1
- data/environment.gemspec +1 -1
- data/lib/environment.rb +31 -4
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -8,11 +8,24 @@ Environment variables in are not available to scripts running as crons and/or se
|
|
8
8
|
|
9
9
|
== Usage
|
10
10
|
|
11
|
-
The global constant ENV is left untouched
|
11
|
+
The global constant ENV is left untouched by default. To read an environment variable, use Environment.get or Environment[].
|
12
12
|
|
13
13
|
Example usage:
|
14
14
|
|
15
15
|
require "rubygems"
|
16
16
|
require "environment"
|
17
17
|
|
18
|
-
|
18
|
+
# the following two are the same
|
19
|
+
path = Environment['PATH']
|
20
|
+
home = Environment.get('HOME')
|
21
|
+
|
22
|
+
If you want to override the default ENV constant, use the override! method
|
23
|
+
|
24
|
+
Example usage:
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "environment"
|
28
|
+
|
29
|
+
host = ENV['HOSTNAME'] #nil
|
30
|
+
Environment.override!
|
31
|
+
host = ENV['HOSTNAME'] #yourdomain.com
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
require "rake"
|
3
3
|
require "echoe"
|
4
4
|
|
5
|
-
Echoe.new("environment", "0.
|
5
|
+
Echoe.new("environment", "0.2.0") do |p|
|
6
6
|
p.description = "Environment variables in are not available to scripts running as crons and/or services. This gem allows ruby scripts running as a cron and/or as a service full access to the system environment variables."
|
7
7
|
p.summary = "Environment variables in are not available to scripts running as crons and/or services. This gem allows ruby scripts running as a cron and/or as a service full access to the system environment variables."
|
8
8
|
p.url = "http://rubygems.org/gems/environment"
|
data/environment.gemspec
CHANGED
data/lib/environment.rb
CHANGED
@@ -9,31 +9,58 @@ Environment variables in are not available to scripts running as crons and/or se
|
|
9
9
|
|
10
10
|
== Usage
|
11
11
|
|
12
|
-
The global constant ENV is left untouched
|
12
|
+
The global constant ENV is left untouched by default. To read an environment variable, use Environment.get or Environment[].
|
13
13
|
|
14
14
|
Example usage:
|
15
15
|
|
16
16
|
require "rubygems"
|
17
17
|
require "environment"
|
18
18
|
|
19
|
-
|
19
|
+
# the following two are the same
|
20
|
+
path = Environment['PATH']
|
21
|
+
home = Environment.get('HOME')
|
22
|
+
|
23
|
+
If you want to override the default ENV constant, use the override! method
|
24
|
+
|
25
|
+
Example usage:
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "environment"
|
29
|
+
|
30
|
+
host = ENV['HOSTNAME'] #nil
|
31
|
+
Environment.override!
|
32
|
+
host = ENV['HOSTNAME'] #yourdomain.com
|
20
33
|
=end
|
21
34
|
module Environment
|
22
35
|
CURRENT_DIR = File.dirname(__FILE__)
|
23
36
|
SHELL_SCRIPT = "#{CURRENT_DIR}/save_environment_variables.sh"
|
24
37
|
VARIABLE_DUMP = "/tmp/.environment_variables"
|
25
|
-
|
38
|
+
@env = {}
|
26
39
|
|
27
40
|
def self.load
|
28
41
|
success = system("bash -l #{SHELL_SCRIPT}")
|
29
42
|
if success && File.exists?(VARIABLE_DUMP)
|
30
43
|
File.read(VARIABLE_DUMP).each_line do |line|
|
31
44
|
key,value = line.split("=")
|
32
|
-
|
45
|
+
@env[key] = value
|
33
46
|
end
|
34
47
|
File.delete(VARIABLE_DUMP)
|
35
48
|
end
|
36
49
|
end
|
50
|
+
|
51
|
+
def self.get(key)
|
52
|
+
return @env[key]
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.[](key)
|
56
|
+
return @env[key]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.override!
|
60
|
+
@env.each do |key,value|
|
61
|
+
ENV[key] = value
|
62
|
+
end
|
63
|
+
end
|
37
64
|
end
|
38
65
|
|
39
66
|
Environment.load
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: environment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nitesh Goel
|