unenviable 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9dbfdf593c2a476c5beb4953b42c7639d7e7c19
4
- data.tar.gz: fbde9bb39e18cef233c4c42e536d455e042d1b79
3
+ metadata.gz: 0f978ca7d7ed85dc730f2fe78215720e823f3ca8
4
+ data.tar.gz: 35e8a1b471130a4ad368b3aef3d694c39070e666
5
5
  SHA512:
6
- metadata.gz: da87b74b624115edfdde1b60d8123f2b59e8db0a13fad38a6c9377a0aef619919868c2e7b4248226f8e2ebb4856cb8f545ca8407ac2849e617b8c859768e34d2
7
- data.tar.gz: 5cba249971d287875434546ffd0a16c772eb8b21ee4d3622291726f34329548210dfae13614557ea7083924ed5c94b87968b9480365d30a3b7c642cc70326f1c
6
+ metadata.gz: be7160d04bdbdd30ffdbc6a5d5f04d02f00e199f9b95f16fd760d68d81134ac4dfc2e3b0c33bf1267b986a8a052def00525aca1cb7f29d1a21dfc778e849ac60
7
+ data.tar.gz: 6e821162b27323a72ea05741ad0835c9c24a76a61fdaa1912f2f8209bd5ce40f714e0aca2264f2cd0d76b0a1d66b31c102e2c3bb525856edbe8375f87e6d1083
data/lib/unenviable.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require 'dotenv'
2
+ require 'dotenv' if Gem::Specification::find_all_by_name('dotenv').any?
3
3
  require 'yaml'
4
4
 
5
5
  require 'unenviable/env_wrapper'
@@ -12,7 +12,7 @@ module Unenviable
12
12
 
13
13
  def self.check
14
14
  load_env_descriptions unless @env_list
15
- Dotenv.load
15
+ Dotenv.load if Gem::Specification::find_all_by_name('dotenv').any?
16
16
  discrepancies = { required: [], optional: [], forbidden: [] }
17
17
 
18
18
  @env_list.each do |var, details|
@@ -39,6 +39,10 @@ module Unenviable
39
39
  Object.const_set(:ENV, wrapper)
40
40
  end
41
41
 
42
+ def self.remove_wrapper
43
+ ENV.restore_saved if ENV.respond_to?(:close_wrapper)
44
+ end
45
+
42
46
  def self.described?(key)
43
47
  @env_list.include?(key)
44
48
  end
@@ -5,12 +5,13 @@ module Unenviable
5
5
  def initialize
6
6
  @saved_env = ENV
7
7
  @closed = false
8
+ @missing_descriptions = []
8
9
  end
9
10
 
10
11
  def [](key)
11
- failed "Requested ENV[#{key}] after initialization finished!" if @closed
12
+ fail "Requested ENV[#{key}] after initialization finished!" if @closed
12
13
  value = @saved_env[key]
13
- fail "Requested ENV[#{key}] which has not been described!" unless Unenviable.described?(key)
14
+ @missing_descriptions << key unless Unenviable.described?(key)
14
15
  return value unless value.nil?
15
16
  'MISSING VALUE'
16
17
  end
@@ -19,8 +20,14 @@ module Unenviable
19
20
  @saved_env[key] = value
20
21
  end
21
22
 
23
+ def restore_saved
24
+ Object.send(:remove_const, :ENV)
25
+ Object.const_set(:ENV, @saved_env)
26
+ end
27
+
22
28
  def close_wrapper
23
29
  @closed = true
30
+ fail "Requested Keys [#{@missing_descriptions.join(', ')}] which are not described!" unless @missing_descriptions.empty?
24
31
  end
25
32
  end
26
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unenviable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - K M Lawrence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv