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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9065b8dcd8d89051b05d62bb500afa9f7c31976f
4
- data.tar.gz: 7540825d1ecf5a0d0d7ae98c2e65e58b2ea31590
3
+ metadata.gz: 30ad142326a0abde1ee4308c62727a5bce561376
4
+ data.tar.gz: 16e73cabe92e3fad22fa71b9da9482ea7b1d6758
5
5
  SHA512:
6
- metadata.gz: 8cf005fbc2dffab23763f4599dd6cbaa7b787526dc2a9abda559af7b7fbea17b943b121ac033907492fe097823add71bec833553e8ceee6ac7baeee6db656beb
7
- data.tar.gz: 5b476c1933bcf831e58c660aac851221e139e7e80237a3a472e95d6bbda69c5c9517cb179310c7d55baf5440eced90e86069a16dc39b90b17d74100f8952706e
6
+ metadata.gz: 365da35f036994b67119dbbbf6072feb7aa931923f561cf450a431a96ec27f2f2afce876bd9a81ed7bc4758cc604551caca7afcd56e78dcbea82bf027f7d4a2b
7
+ data.tar.gz: 0de76d7286a75eb0aceb3fe049fc8b18d6aabf5de4dd77f2f6098fc0b8b578e2b11ebe6a8853838112e84e2f2d81d5a6d8de67fc806f6cd0de149911592b5f0d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .idea/
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
@@ -1,3 +1,3 @@
1
1
  module Environ
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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
- def all
16
- ENV
17
- end
41
+ def all
42
+ ENV
43
+ end
18
44
 
19
- # Public: Resets all environment variables back to their original values
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
- def reset!
27
- @_data.clear
28
- create_methods
29
- end
52
+ def reset!
53
+ @_data.clear
54
+ create_methods
55
+ end
30
56
 
31
- def method_missing(method, *args, &block)
32
- if (method.to_s =~ /env_/)
33
- create_method(method.to_s, nil)
34
- nil
35
- else
36
- super.method_missing(method, *args, &block)
37
- end
38
- end
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
- def create_methods
48
- ENV.each do |key, val|
49
- create_method(key, val)
50
- end
51
- end
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
- def create_method(name, val)
61
- var_name = "env_#{name.strip.downcase}"
62
- @_data[var_name] = val
63
- define_singleton_method(var_name) do
64
- @_data[var_name]
65
- end
66
-
67
- define_singleton_method(:"#{var_name}=") do |value|
68
- @_data[var_name] = value
69
- end
70
- end
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
- self.create_methods
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.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-08 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler