dotenv 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +30 -2
- data/Gemfile +5 -1
- data/Guardfile +9 -0
- data/README.md +9 -8
- data/Rakefile +13 -3
- data/dotenv-rails.gemspec +17 -0
- data/dotenv.gemspec +2 -1
- data/lib/dotenv-rails.rb +2 -0
- data/lib/dotenv.rb +1 -0
- data/lib/dotenv/environment.rb +10 -1
- data/lib/dotenv/railtie.rb +21 -0
- data/lib/dotenv/version.rb +3 -0
- data/spec/dotenv/environment_spec.rb +72 -0
- data/spec/dotenv_spec.rb +1 -78
- data/spec/fixtures/exported.env +2 -0
- data/spec/fixtures/quoted.env +4 -0
- data/spec/spec_helper.rb +7 -1
- metadata +10 -8
data/Changelog.md
CHANGED
@@ -1,17 +1,45 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.6.0 - Mar 22, 2013
|
4
|
+
|
5
|
+
* Add dotenv-rails gem for autoloading in a Rails app
|
6
|
+
|
7
|
+
* Deprecated autoloading with plain dotenv gem
|
8
|
+
|
9
|
+
* Support for double quotes
|
10
|
+
|
11
|
+
A="some value"
|
12
|
+
B="with \"escaped\" quotes"
|
13
|
+
C="and newline\n expansion"
|
14
|
+
|
15
|
+
* Support for pow-style variables prefixed with export
|
16
|
+
|
17
|
+
export VARIABLE="some value"
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.5.0...v0.6.0)
|
20
|
+
|
3
21
|
## 0.5.0 - Jan 25, 2013
|
4
22
|
|
5
23
|
* Load immediately on require in Rails instead of waiting for initialization
|
24
|
+
|
6
25
|
* Add YAML-style variables
|
7
|
-
|
26
|
+
|
27
|
+
VARIABLE: some value
|
28
|
+
|
29
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.4.0...v0.5.0)
|
8
30
|
|
9
31
|
## 0.4.0 - Nov 13, 2012
|
10
32
|
|
11
33
|
* Add support for quoted options, e.g.:
|
12
|
-
|
34
|
+
|
35
|
+
VARIABLE='some value'
|
36
|
+
|
13
37
|
* Fix rake deprecation warnings
|
14
38
|
|
39
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.3.0...v0.4.0)
|
40
|
+
|
15
41
|
## 0.3.0 - Oct 25, 2012
|
16
42
|
|
17
43
|
* Avoid overriding existing ENV variables so values set before loading the app are maintained.
|
44
|
+
|
45
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.2.0...v0.3.0)
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Read more about the [motivation for dotenv at opensoul.org](http://opensoul.org/
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'dotenv', :groups => [:development, :test]
|
14
|
+
gem 'dotenv-rails', :groups => [:development, :test]
|
15
15
|
```
|
16
16
|
|
17
17
|
And then execute:
|
@@ -43,25 +43,26 @@ end
|
|
43
43
|
|
44
44
|
## Usage
|
45
45
|
|
46
|
-
Add your application configuration to `.env
|
46
|
+
Add your application configuration to your `.env` file in the root of
|
47
|
+
your project:
|
47
48
|
|
48
49
|
```shell
|
49
|
-
S3_BUCKET=
|
50
|
-
SECRET_KEY=
|
50
|
+
S3_BUCKET=YOURS3BUCKET
|
51
|
+
SECRET_KEY=YOURSECRETKEYGOESHERE
|
51
52
|
```
|
52
53
|
|
53
54
|
You can also create files per environment, such as `.env.test`:
|
54
55
|
|
55
56
|
```shell
|
56
|
-
S3_BUCKET=
|
57
|
-
SECRET_KEY=
|
57
|
+
S3_BUCKET=tests3bucket
|
58
|
+
SECRET_KEY=testsecretkey
|
58
59
|
```
|
59
60
|
|
60
61
|
An alternate yaml-like syntax is supported:
|
61
62
|
|
62
63
|
```yaml
|
63
|
-
S3_BUCKET:
|
64
|
-
SECRET_KEY:
|
64
|
+
S3_BUCKET: yamlstyleforyours3bucket
|
65
|
+
SECRET_KEY: thisisalsoanokaysecret
|
65
66
|
```
|
66
67
|
|
67
68
|
Whenever your application loads, these variables will be available in `ENV`:
|
data/Rakefile
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
|
2
|
+
|
3
|
+
require 'bundler/gem_helper'
|
4
|
+
%w(dotenv dotenv-rails).each do |name|
|
5
|
+
namespace name do
|
6
|
+
Bundler::GemHelper.install_tasks :name => name
|
7
|
+
end
|
8
|
+
|
9
|
+
task :build => "#{name}:build"
|
10
|
+
task :install => "#{name}:install"
|
11
|
+
task :release => "#{name}:release"
|
12
|
+
end
|
13
|
+
|
3
14
|
require 'rspec/core/rake_task'
|
4
15
|
|
5
16
|
desc "Run all specs"
|
@@ -8,5 +19,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
8
19
|
t.verbose = false
|
9
20
|
end
|
10
21
|
|
11
|
-
|
12
|
-
task :default => :spec
|
22
|
+
task :default => :spec
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dotenv/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.version = Dotenv::VERSION
|
6
|
+
gem.authors = ["Brandon Keepers"]
|
7
|
+
gem.email = ["brandon@opensoul.org"]
|
8
|
+
gem.description = %q{Autoload dotenv in Rails.}
|
9
|
+
gem.summary = %q{Autoload dotenv in Rails.}
|
10
|
+
gem.homepage = "https://github.com/bkeepers/dotenv"
|
11
|
+
|
12
|
+
gem.files = ["lib/dotenv-rails.rb"]
|
13
|
+
gem.name = "dotenv-rails"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
|
16
|
+
gem.add_dependency 'dotenv', Dotenv::VERSION
|
17
|
+
end
|
data/dotenv.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dotenv/version', __FILE__)
|
2
3
|
|
3
4
|
Gem::Specification.new do |gem|
|
4
|
-
gem.version =
|
5
|
+
gem.version = Dotenv::VERSION
|
5
6
|
gem.authors = ["Brandon Keepers"]
|
6
7
|
gem.email = ["brandon@opensoul.org"]
|
7
8
|
gem.description = %q{Loads environment variables from `.env`.}
|
data/lib/dotenv-rails.rb
ADDED
data/lib/dotenv.rb
CHANGED
data/lib/dotenv/environment.rb
CHANGED
@@ -7,7 +7,16 @@ module Dotenv
|
|
7
7
|
|
8
8
|
def load
|
9
9
|
read.each do |line|
|
10
|
-
|
10
|
+
if line =~ /\A(?:export\s+)?(\w+)(?:=|: ?)(.*)\z/
|
11
|
+
key = $1
|
12
|
+
case val = $2
|
13
|
+
# Remove single quotes
|
14
|
+
when /\A'(.*)'\z/ then self[key] = $1
|
15
|
+
# Remove double quotes and unescape string preserving newline characters
|
16
|
+
when /\A"(.*)"\z/ then self[key] = $1.gsub('\n', "\n").gsub(/\\(.)/, '\1')
|
17
|
+
else self[key] = val
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
data/lib/dotenv/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
|
1
3
|
module Dotenv
|
2
4
|
class Railtie < Rails::Railtie
|
3
5
|
include Rake::DSL if defined?(Rake)
|
@@ -8,6 +10,25 @@ module Dotenv
|
|
8
10
|
Dotenv.load ".env.#{Rails.env}", '.env'
|
9
11
|
end
|
10
12
|
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def no_warn!
|
16
|
+
@no_warn = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def no_warn?
|
20
|
+
@no_warn
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
initializer 'dotenv', :group => :all do
|
25
|
+
unless self.class.no_warn?
|
26
|
+
warn <<-EOF
|
27
|
+
[DEPRECATION] Autoloading for dotenv has been moved to the `dotenv-rails` gem. Change your Gemfile to:
|
28
|
+
gem 'dotenv-rails', :groups => [:development, :test]
|
29
|
+
EOF
|
30
|
+
end
|
31
|
+
end
|
11
32
|
end
|
12
33
|
end
|
13
34
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dotenv::Environment do
|
4
|
+
subject { env("OPTION_A=1\nOPTION_B=2") }
|
5
|
+
|
6
|
+
describe 'initialize' do
|
7
|
+
it 'reads the file' do
|
8
|
+
expect(subject['OPTION_A']).to eq('1')
|
9
|
+
expect(subject['OPTION_B']).to eq('2')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'apply' do
|
14
|
+
it 'sets variables in ENV' do
|
15
|
+
subject.apply
|
16
|
+
expect(ENV['OPTION_A']).to eq('1')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not override defined variables' do
|
20
|
+
ENV['OPTION_A'] = 'predefined'
|
21
|
+
subject.apply
|
22
|
+
expect(ENV['OPTION_A']).to eq('predefined')
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when the file does not exist' do
|
26
|
+
subject { Dotenv::Environment.new('.env_does_not_exist') }
|
27
|
+
|
28
|
+
it 'fails silently' do
|
29
|
+
expect { subject.apply }.not_to raise_error
|
30
|
+
expect(ENV.keys).to eq(@env_keys)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'parses unquoted values' do
|
36
|
+
expect(env('FOO=bar')).to eql({'FOO' => 'bar'})
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'parses double quoted values' do
|
40
|
+
expect(env('FOO="bar"')).to eql({'FOO' => 'bar'})
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'parses single quoted values' do
|
44
|
+
expect(env("FOO='bar'")).to eql({'FOO' => 'bar'})
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'parses escaped double quotes' do
|
48
|
+
expect(env('FOO="escaped\"bar"')).to eql({'FOO' => 'escaped"bar'})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'parses yaml style options' do
|
52
|
+
expect(env("OPTION_A: 1")).to eql('OPTION_A' => '1')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'parses export keyword' do
|
56
|
+
expect(env("export OPTION_A=2")).to eql('OPTION_A' => '2')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'expands newlines in quoted strings' do
|
60
|
+
expect(env('FOO="bar\nbaz"')).to eql({"FOO" => "bar\nbaz"})
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'tempfile'
|
64
|
+
def env(text)
|
65
|
+
file = Tempfile.new('dotenv')
|
66
|
+
file.write text
|
67
|
+
file.close
|
68
|
+
env = Dotenv::Environment.new(file.path)
|
69
|
+
file.unlink
|
70
|
+
env
|
71
|
+
end
|
72
|
+
end
|
data/spec/dotenv_spec.rb
CHANGED
@@ -3,14 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Dotenv do
|
4
4
|
let(:env_path) { fixture_path('plain.env') }
|
5
5
|
|
6
|
-
before do
|
7
|
-
@env_keys = ENV.keys
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
ENV.delete_if { |k,v| !@env_keys.include?(k) }
|
12
|
-
end
|
13
|
-
|
14
6
|
describe 'load' do
|
15
7
|
context 'with no args' do
|
16
8
|
it 'defaults to .env' do
|
@@ -39,79 +31,10 @@ describe Dotenv do
|
|
39
31
|
it 'returns hash of loaded environments' do
|
40
32
|
expect(subject).to eq(expected)
|
41
33
|
end
|
42
|
-
|
43
|
-
context 'with quoted file' do
|
44
|
-
let(:expected) do
|
45
|
-
{'OPTION_A' => '1', 'OPTION_B' => '2', 'OPTION_C' => '', 'OPTION_D' => '\n', 'DOTENV' => 'true'}
|
46
|
-
end
|
47
|
-
let(:env_path) { fixture_path('quoted.env') }
|
48
|
-
|
49
|
-
it 'returns hash of loaded environments' do
|
50
|
-
expect(subject).to eq(expected)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with yaml file' do
|
56
|
-
let(:expected) do
|
57
|
-
{'OPTION_A' => '1', 'OPTION_B' => '2', 'OPTION_C' => '', 'OPTION_D' => '\n', 'DOTENV' => 'true'}
|
58
|
-
end
|
59
|
-
let(:env_path) { fixture_path('yaml.env') }
|
60
|
-
|
61
|
-
it 'returns hash of loaded environments' do
|
62
|
-
expect(subject).to eq(expected)
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
34
|
end
|
67
35
|
end
|
68
36
|
|
69
|
-
describe Dotenv::Environment do
|
70
|
-
subject { Dotenv::Environment.new(env_path) }
|
71
|
-
|
72
|
-
context 'with a plain env file' do
|
73
|
-
|
74
|
-
describe 'initialize' do
|
75
|
-
it 'reads environment config' do
|
76
|
-
expect(subject['OPTION_A']).to eq('1')
|
77
|
-
expect(subject['OPTION_B']).to eq('2')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'apply' do
|
82
|
-
it 'sets variables in ENV' do
|
83
|
-
subject.apply
|
84
|
-
expect(ENV['OPTION_A']).to eq('1')
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'does not override defined variables' do
|
88
|
-
ENV['OPTION_A'] = 'predefined'
|
89
|
-
subject.apply
|
90
|
-
expect(ENV['OPTION_A']).to eq('predefined')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'when the file does not exist' do
|
96
|
-
let(:env_path) { fixture_path('.env_does_not_exist') }
|
97
|
-
|
98
|
-
describe 'initialize' do
|
99
|
-
it 'fails silently' do
|
100
|
-
expect { Dotenv::Environment.new('.env_does_not_exist') }.not_to raise_error
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe 'apply' do
|
105
|
-
it 'does not effect env' do
|
106
|
-
subject.apply
|
107
|
-
expect(ENV.keys).to eq(@env_keys)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
37
|
def fixture_path(name)
|
115
38
|
File.join(File.expand_path('../fixtures', __FILE__), name)
|
116
39
|
end
|
117
|
-
end
|
40
|
+
end
|
data/spec/fixtures/quoted.env
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -55,15 +55,21 @@ files:
|
|
55
55
|
- .travis.yml
|
56
56
|
- Changelog.md
|
57
57
|
- Gemfile
|
58
|
+
- Guardfile
|
58
59
|
- LICENSE
|
59
60
|
- README.md
|
60
61
|
- Rakefile
|
62
|
+
- dotenv-rails.gemspec
|
61
63
|
- dotenv.gemspec
|
64
|
+
- lib/dotenv-rails.rb
|
62
65
|
- lib/dotenv.rb
|
63
66
|
- lib/dotenv/environment.rb
|
64
67
|
- lib/dotenv/railtie.rb
|
65
68
|
- lib/dotenv/tasks.rb
|
69
|
+
- lib/dotenv/version.rb
|
70
|
+
- spec/dotenv/environment_spec.rb
|
66
71
|
- spec/dotenv_spec.rb
|
72
|
+
- spec/fixtures/exported.env
|
67
73
|
- spec/fixtures/plain.env
|
68
74
|
- spec/fixtures/quoted.env
|
69
75
|
- spec/fixtures/yaml.env
|
@@ -80,18 +86,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
86
|
- - ! '>='
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0'
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
hash: -3615033000965864371
|
86
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
90
|
none: false
|
88
91
|
requirements:
|
89
92
|
- - ! '>='
|
90
93
|
- !ruby/object:Gem::Version
|
91
94
|
version: '0'
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: -3615033000965864371
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
97
|
rubygems_version: 1.8.23
|
@@ -99,7 +99,9 @@ signing_key:
|
|
99
99
|
specification_version: 3
|
100
100
|
summary: Loads environment variables from `.env`.
|
101
101
|
test_files:
|
102
|
+
- spec/dotenv/environment_spec.rb
|
102
103
|
- spec/dotenv_spec.rb
|
104
|
+
- spec/fixtures/exported.env
|
103
105
|
- spec/fixtures/plain.env
|
104
106
|
- spec/fixtures/quoted.env
|
105
107
|
- spec/fixtures/yaml.env
|