dotenv 0.1.0 → 0.2.0
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.
- data/.env +1 -0
- data/README.md +7 -2
- data/dotenv.gemspec +1 -1
- data/lib/dotenv/environment.rb +1 -1
- data/lib/dotenv/railtie.rb +1 -1
- data/lib/dotenv.rb +6 -3
- data/spec/dotenv_spec.rb +65 -10
- metadata +5 -4
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# dotenv
|
|
2
2
|
|
|
3
|
-
Loads environment
|
|
3
|
+
Loads environment variables from `.env` into `ENV`, automagically.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Read more about the [motivation for dotenv at opensoul.org](http://opensoul.org/blog/archives/2012/07/24/dotenv/).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -41,6 +41,11 @@ Add your application configuration to `.env`.
|
|
|
41
41
|
S3_BUCKET=dotenv
|
|
42
42
|
SECRET_KEY=sssshhh!
|
|
43
43
|
|
|
44
|
+
You can also create files per environment, such as `.env.test`:
|
|
45
|
+
|
|
46
|
+
S3_BUCKET=test
|
|
47
|
+
SECRET_KEY=test
|
|
48
|
+
|
|
44
49
|
Whenever your application loads, these variables will be available in `ENV`:
|
|
45
50
|
|
|
46
51
|
config.fog_directory = ENV['S3_BUCKET']
|
data/dotenv.gemspec
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |gem|
|
|
4
|
+
gem.version = '0.2.0'
|
|
4
5
|
gem.authors = ["Brandon Keepers"]
|
|
5
6
|
gem.email = ["brandon@opensoul.org"]
|
|
6
7
|
gem.description = %q{Loads environment variables from `.env`.}
|
|
@@ -12,7 +13,6 @@ Gem::Specification.new do |gem|
|
|
|
12
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
13
14
|
gem.name = "dotenv"
|
|
14
15
|
gem.require_paths = ["lib"]
|
|
15
|
-
gem.version = '0.1.0'
|
|
16
16
|
|
|
17
17
|
gem.add_development_dependency 'rake'
|
|
18
18
|
gem.add_development_dependency 'rspec'
|
data/lib/dotenv/environment.rb
CHANGED
data/lib/dotenv/railtie.rb
CHANGED
data/lib/dotenv.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require 'dotenv/environment'
|
|
2
2
|
|
|
3
3
|
module Dotenv
|
|
4
|
-
def self.load(
|
|
5
|
-
|
|
4
|
+
def self.load(*filenames)
|
|
5
|
+
filenames << '.env' if filenames.empty?
|
|
6
|
+
filenames.inject({}) do |hash, filename|
|
|
7
|
+
hash.merge Dotenv::Environment.new(filename).apply
|
|
8
|
+
end
|
|
6
9
|
end
|
|
7
10
|
end
|
|
8
11
|
|
|
9
|
-
require 'dotenv/railtie' if defined?(Rails)
|
|
12
|
+
require 'dotenv/railtie' if defined?(Rails) and defined?(Rails::Railtie)
|
data/spec/dotenv_spec.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Dotenv
|
|
3
|
+
describe Dotenv do
|
|
4
4
|
let(:env_path) { fixture_path('plain.env') }
|
|
5
|
-
let(:dotenv) { Dotenv::Environment.new(env_path) }
|
|
6
5
|
|
|
7
6
|
before do
|
|
8
7
|
@env_keys = ENV.keys
|
|
@@ -12,18 +11,74 @@ describe Dotenv::Environment do
|
|
|
12
11
|
ENV.delete_if { |k,v| !@env_keys.include?(k) }
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
describe '
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
describe 'load' do
|
|
15
|
+
context 'with no args' do
|
|
16
|
+
it 'defaults to .env' do
|
|
17
|
+
Dotenv::Environment.should_receive(:new).with('.env').
|
|
18
|
+
and_return(mock(:apply => {}))
|
|
19
|
+
Dotenv.load
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'with multiple files' do
|
|
24
|
+
let(:expected) do
|
|
25
|
+
{'OPTION_A' => '1', 'OPTION_B' => '2', 'DOTENV' => 'true'}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
subject do
|
|
29
|
+
Dotenv.load('.env', env_path)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'loads all files' do
|
|
33
|
+
subject
|
|
34
|
+
expected.each do |key, value|
|
|
35
|
+
expect(ENV[key]).to eq(value)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns hash of loaded environments' do
|
|
40
|
+
expect(subject).to eq(expected)
|
|
41
|
+
end
|
|
19
42
|
end
|
|
20
43
|
end
|
|
21
44
|
|
|
22
|
-
describe
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
describe Dotenv::Environment do
|
|
46
|
+
subject { Dotenv::Environment.new(env_path) }
|
|
47
|
+
|
|
48
|
+
context 'with a plain env file' do
|
|
49
|
+
|
|
50
|
+
describe 'initialize' do
|
|
51
|
+
it 'reads environment config' do
|
|
52
|
+
expect(subject['OPTION_A']).to eq('1')
|
|
53
|
+
expect(subject['OPTION_B']).to eq('2')
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'apply' do
|
|
58
|
+
it 'sets variables in ENV' do
|
|
59
|
+
subject.apply
|
|
60
|
+
expect(ENV['OPTION_A']).to eq('1')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'when the file does not exist' do
|
|
66
|
+
let(:env_path) { fixture_path('.env_does_not_exist') }
|
|
67
|
+
|
|
68
|
+
describe 'initialize' do
|
|
69
|
+
it 'fails silently' do
|
|
70
|
+
expect { Dotenv::Environment.new('.env_does_not_exist') }.not_to raise_error
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'apply' do
|
|
75
|
+
it 'does not effect env' do
|
|
76
|
+
subject.apply
|
|
77
|
+
expect(ENV.keys).to eq(@env_keys)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
26
80
|
end
|
|
81
|
+
|
|
27
82
|
end
|
|
28
83
|
|
|
29
84
|
def fixture_path(name)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dotenv
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 2
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.2.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Brandon Keepers
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-
|
|
18
|
+
date: 2012-09-06 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: rake
|
|
@@ -55,6 +55,7 @@ extensions: []
|
|
|
55
55
|
extra_rdoc_files: []
|
|
56
56
|
|
|
57
57
|
files:
|
|
58
|
+
- .env
|
|
58
59
|
- .gitignore
|
|
59
60
|
- Gemfile
|
|
60
61
|
- LICENSE
|