environ 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +7 -0
- data/lib/environ/version.rb +1 -1
- data/lib/environ.rb +59 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ad142326a0abde1ee4308c62727a5bce561376
|
4
|
+
data.tar.gz: 16e73cabe92e3fad22fa71b9da9482ea7b1d6758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365da35f036994b67119dbbbf6072feb7aa931923f561cf450a431a96ec27f2f2afce876bd9a81ed7bc4758cc604551caca7afcd56e78dcbea82bf027f7d4a2b
|
7
|
+
data.tar.gz: 0de76d7286a75eb0aceb3fe049fc8b18d6aabf5de4dd77f2f6098fc0b8b578e2b11ebe6a8853838112e84e2f2d81d5a6d8de67fc806f6cd0de149911592b5f0d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,13 @@ You can also access all the keys in the environment with:
|
|
43
43
|
|
44
44
|
This will return a hash of all the environment variables.
|
45
45
|
|
46
|
+
If you choose to live on the edge, you can also disable no-conflict support and access variables directly by their ENV name:
|
47
|
+
|
48
|
+
Environ.no_conflict = false
|
49
|
+
path = Environ.path
|
50
|
+
|
51
|
+
No conflict is true by default to prevent unexpected results.
|
52
|
+
|
46
53
|
Finally, Environ respects accessing variables that may not be set. If you call something like `Environ.env_doesnt_exist` it will return nil rather than throw an exception.
|
47
54
|
|
48
55
|
## Development
|
data/lib/environ/version.rb
CHANGED
data/lib/environ.rb
CHANGED
@@ -3,7 +3,33 @@ require_relative "environ/version"
|
|
3
3
|
# Public: Main handler for accessing variables
|
4
4
|
module Environ
|
5
5
|
module_function
|
6
|
+
|
6
7
|
@_data = {}
|
8
|
+
@_no_conflict = true
|
9
|
+
|
10
|
+
# Public: Returns boolean indicating whether no conflict prefixing is on or off
|
11
|
+
#
|
12
|
+
# Examples
|
13
|
+
#
|
14
|
+
# Environ.no_conflict => true
|
15
|
+
#
|
16
|
+
# returns boolean
|
17
|
+
def no_conflict
|
18
|
+
@_no_conflict
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Sets boolean indicating whether no conflict prefixing is on or off
|
22
|
+
# If set to false, env vars can be accessed without the 'env_' prefix
|
23
|
+
# Examples
|
24
|
+
#
|
25
|
+
# Environ.no_conflict = false
|
26
|
+
# Environ.path => {"PATH"=>"/Users/someone/.rvm/gems/ruby-2.2.0/bin", "RUBY_VERSION"=>"ruby-2.2.0", "_"=>"/Users/someone/.rvm/rubies/ruby-2.2.0/bin/irb"}
|
27
|
+
#
|
28
|
+
# returns nothing
|
29
|
+
def no_conflict=(value)
|
30
|
+
@_no_conflict = value
|
31
|
+
create_methods unless @_no_conflict
|
32
|
+
end
|
7
33
|
|
8
34
|
# Public: Returns all environment variables as hash
|
9
35
|
#
|
@@ -12,30 +38,30 @@ module Environ
|
|
12
38
|
# Environ.all => {"PATH"=>"/Users/someone/.rvm/gems/ruby-2.2.0/bin", "RUBY_VERSION"=>"ruby-2.2.0", "_"=>"/Users/someone/.rvm/rubies/ruby-2.2.0/bin/irb"}
|
13
39
|
#
|
14
40
|
# returns hash of all variables
|
15
|
-
|
16
|
-
|
17
|
-
|
41
|
+
def all
|
42
|
+
ENV
|
43
|
+
end
|
18
44
|
|
19
|
-
|
45
|
+
# Public: Resets all environment variables back to their original values
|
20
46
|
#
|
21
47
|
# Examples
|
22
48
|
#
|
23
49
|
# Environ.reset!
|
24
50
|
#
|
25
51
|
# returns nothing
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
52
|
+
def reset!
|
53
|
+
@_data.clear
|
54
|
+
create_methods
|
55
|
+
end
|
30
56
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
57
|
+
def method_missing(method, *args, &block)
|
58
|
+
if (method.to_s =~ /env_/)
|
59
|
+
create_method(method.to_s, nil)
|
60
|
+
nil
|
61
|
+
else
|
62
|
+
super.method_missing(method, *args, &block)
|
63
|
+
end
|
64
|
+
end
|
39
65
|
|
40
66
|
# Public: Dynamically defines singleton methods from ENV
|
41
67
|
#
|
@@ -44,11 +70,11 @@ module Environ
|
|
44
70
|
# Environ.create_methods
|
45
71
|
#
|
46
72
|
# returns nothing
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
73
|
+
def create_methods
|
74
|
+
ENV.each do |key, val|
|
75
|
+
create_method(key, val)
|
76
|
+
end
|
77
|
+
end
|
52
78
|
|
53
79
|
# Public: Dynamically defines a singleton method
|
54
80
|
#
|
@@ -57,19 +83,19 @@ module Environ
|
|
57
83
|
# Environ.create_method('path', 'something')
|
58
84
|
#
|
59
85
|
# returns nothing
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
86
|
+
def create_method(name, val)
|
87
|
+
var_prefix = @_no_conflict ? 'env_' : ''
|
88
|
+
var_name = "#{var_prefix}#{name.strip.downcase}"
|
89
|
+
@_data[var_name] = val
|
90
|
+
define_singleton_method(var_name) do
|
91
|
+
@_data[var_name]
|
92
|
+
end
|
93
|
+
define_singleton_method(:"#{var_name}=") do |value|
|
94
|
+
@_data[var_name] = value
|
95
|
+
end
|
96
|
+
end
|
71
97
|
|
72
98
|
# initialize methods
|
73
|
-
|
99
|
+
self.create_methods
|
74
100
|
|
75
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: environ
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mondok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|