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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ced7332ac2a27ac268f334af2a886672818f3830
4
- data.tar.gz: 1b6ba14c478f1610e173f3a29234a97fe4727bb9
3
+ metadata.gz: 687c210305951dcf6b7629568a0769fc0c283c40
4
+ data.tar.gz: a57f042d16d9074bb1f5008d7110aa0f75695534
5
5
  SHA512:
6
- metadata.gz: 43b8ddc20ff10804d0f74a4b9b126277191c81e8165caf1517c1a454764959c27fd0953c639e3a9e636cb3cd30550763a8ae6ecf8fefb2ffb0672b3b62164430
7
- data.tar.gz: 2f5c62c157b1ca0b0d0a90f5d6dc71ff47d27af32ff863813b79ee5fde20e62684d8445730b357355144b335e9451c676f699910e3ab7df0613f5c35da16b87a
6
+ metadata.gz: 60b454fce0770b1c271bb91d81fbfb70492e8af458aa75f845dae147aa92c11160fda50c732d88ad9d82581b7a1c592c24c082db6c7239cce819341480083e7c
7
+ data.tar.gz: 8d173935d50cc23b8744f03641e5b01bcc6cc14165d4470cf7d24fbc442db12bf4261e890c029f64e4b86fc771b540090ed166ed234b5c0a4dabe803e5fe7ea6
@@ -1,4 +1,7 @@
1
1
  # CHANGELOG.md for denv
2
+ ## 0.2.2
3
+ - Env vars are removed on loading when they are removed from `.env` file. This is useful when use unicorn's graceful reloading.
4
+
2
5
  ## 0.2.1
3
6
  - Add command line tool (`denv`)
4
7
 
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
@@ -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
- ENV.update(build_env(filename))
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)
@@ -1,3 +1,3 @@
1
1
  module Denv
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -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.1
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 00:00:00.000000000 Z
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