denv 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/lib/denv.rb +17 -3
- data/lib/denv/version.rb +1 -1
- data/reload_env_test.rb +26 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 687c210305951dcf6b7629568a0769fc0c283c40
|
4
|
+
data.tar.gz: a57f042d16d9074bb1f5008d7110aa0f75695534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b454fce0770b1c271bb91d81fbfb70492e8af458aa75f845dae147aa92c11160fda50c732d88ad9d82581b7a1c592c24c082db6c7239cce819341480083e7c
|
7
|
+
data.tar.gz: 8d173935d50cc23b8744f03641e5b01bcc6cc14165d4470cf7d24fbc442db12bf4261e890c029f64e4b86fc771b540090ed166ed234b5c0a4dabe803e5fe7ea6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Loads environment variables to `ENV` from `.env` file.
|
|
7
7
|
|
8
8
|
- No special treatments about shell meta characters (e.g. `$`).
|
9
9
|
- Behaves as over-write.
|
10
|
+
- Env vars are removed on loading when they are removed from `.env` file. This is useful when use unicorn's graceful reloading.
|
10
11
|
|
11
12
|
## Usage
|
12
13
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ end
|
|
10
10
|
desc 'Run all tests'
|
11
11
|
task :test do
|
12
12
|
Rake::Task[:spec].invoke
|
13
|
+
Rake::Task[:reload_env_test].invoke
|
13
14
|
Rake::Task[:integration_test].invoke
|
14
15
|
end
|
15
16
|
|
@@ -21,3 +22,8 @@ end
|
|
21
22
|
def execute_without_bundler
|
22
23
|
defined?(Bundler) ? Bundler.with_clean_env { yield } : yield
|
23
24
|
end
|
25
|
+
|
26
|
+
desc 'Run reload_env_test'
|
27
|
+
task :reload_env_test do
|
28
|
+
exit(1) unless ruby('reload_env_test.rb')
|
29
|
+
end
|
data/lib/denv.rb
CHANGED
@@ -23,6 +23,8 @@ module Denv
|
|
23
23
|
end
|
24
24
|
|
25
25
|
DEFAULT_ENV_FILENAME = '.env'.freeze
|
26
|
+
SPECIAL_KEY = '__denv_previous_keys__'.freeze
|
27
|
+
DELIMITER = '='.freeze
|
26
28
|
|
27
29
|
class << self
|
28
30
|
attr_accessor :callback
|
@@ -34,7 +36,10 @@ module Denv
|
|
34
36
|
def load(filename = DEFAULT_ENV_FILENAME)
|
35
37
|
filename = File.expand_path(filename.to_s)
|
36
38
|
run_callback(filename) do
|
37
|
-
|
39
|
+
remove_previous_denv_envs
|
40
|
+
env = build_env(filename)
|
41
|
+
ENV.update(env)
|
42
|
+
ENV[SPECIAL_KEY] = env.keys.join(DELIMITER)
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
@@ -47,6 +52,15 @@ module Denv
|
|
47
52
|
|
48
53
|
private
|
49
54
|
|
55
|
+
def remove_previous_denv_envs
|
56
|
+
return unless ENV[SPECIAL_KEY]
|
57
|
+
|
58
|
+
previous_keys = ENV[SPECIAL_KEY].split(DELIMITER)
|
59
|
+
unless previous_keys.empty?
|
60
|
+
ENV.delete_if {|k, _| previous_keys.include?(k) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
50
64
|
def open_file(filename)
|
51
65
|
File.open(filename) {|f| yield f }
|
52
66
|
rescue Errno::ENOENT
|
@@ -60,8 +74,8 @@ module Denv
|
|
60
74
|
end
|
61
75
|
|
62
76
|
class Parser
|
63
|
-
COMMENT_CHAR = '#'
|
64
|
-
DELIMITER = '='
|
77
|
+
COMMENT_CHAR = '#'.freeze
|
78
|
+
DELIMITER = '='.freeze
|
65
79
|
WHITE_SPACES = /\s/
|
66
80
|
|
67
81
|
def initialize(io, filename)
|
data/lib/denv/version.rb
CHANGED
data/reload_env_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'denv'
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
FileUtils.rm_rf('tmp')
|
8
|
+
FileUtils.mkdir_p('tmp')
|
9
|
+
Dir.chdir('tmp') do
|
10
|
+
ENV['INIT'] = '1'
|
11
|
+
File.write('.env', "XXX=1\nYYY=2\n")
|
12
|
+
Denv.load
|
13
|
+
raise('Necessary keys are removed') unless ENV.has_key?('INIT')
|
14
|
+
raise('Can not set env') unless ENV['YYY'] == '2'
|
15
|
+
|
16
|
+
File.write('.env', "XXX=1\n")
|
17
|
+
code = <<-EOS
|
18
|
+
$LOAD_PATH.unshift("#{lib}")
|
19
|
+
require 'denv'
|
20
|
+
Denv.load
|
21
|
+
raise('Previous env vars are not removed') if ENV.has_key?('YYY')
|
22
|
+
raise('Necessary keys are removed') unless ENV.has_key?('XXX')
|
23
|
+
puts 'Success'
|
24
|
+
EOS
|
25
|
+
exec('ruby', '-e', code)
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: denv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taiki Ono
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/denv/rails.rb
|
92
92
|
- lib/denv/version.rb
|
93
93
|
- rails_integration_test.rb
|
94
|
+
- reload_env_test.rb
|
94
95
|
homepage: https://github.com/taiki45/denv
|
95
96
|
licenses:
|
96
97
|
- MIT
|