dotenv 0.1.1 → 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 ADDED
@@ -0,0 +1 @@
1
+ DOTENV=true
data/README.md CHANGED
@@ -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']
@@ -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.1'
16
16
 
17
17
  gem.add_development_dependency 'rake'
18
18
  gem.add_development_dependency 'rspec'
@@ -1,8 +1,11 @@
1
1
  require 'dotenv/environment'
2
2
 
3
3
  module Dotenv
4
- def self.load(filename = '.env')
5
- Dotenv::Environment.new(filename).apply
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
 
@@ -5,7 +5,7 @@ module Dotenv
5
5
  end
6
6
 
7
7
  initializer 'dotenv', :group => :all do
8
- Dotenv.load
8
+ Dotenv.load '.env', ".env.#{Rails.env}"
9
9
  end
10
10
  end
11
11
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dotenv::Environment do
4
- let(:dotenv) { Dotenv::Environment.new(env_path) }
3
+ describe Dotenv do
4
+ let(:env_path) { fixture_path('plain.env') }
5
5
 
6
6
  before do
7
7
  @env_keys = ENV.keys
@@ -11,39 +11,74 @@ describe Dotenv::Environment do
11
11
  ENV.delete_if { |k,v| !@env_keys.include?(k) }
12
12
  end
13
13
 
14
- context 'with a plain env file' do
15
- let(:env_path) { fixture_path('plain.env') }
16
-
17
- describe 'initialize' do
18
- it 'reads environment config' do
19
- expect(dotenv['OPTION_A']).to eq('1')
20
- expect(dotenv['OPTION_B']).to eq('2')
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
21
20
  end
22
21
  end
23
22
 
24
- describe 'apply' do
25
- it 'sets variables in ENV' do
26
- dotenv.apply
27
- expect(ENV['OPTION_A']).to eq('1')
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)
28
41
  end
29
42
  end
30
43
  end
31
44
 
32
- context 'when the file does not exist' do
33
- let(:env_path) { fixture_path('.env_does_not_exist') }
45
+ describe Dotenv::Environment do
46
+ subject { Dotenv::Environment.new(env_path) }
34
47
 
35
- describe 'initialize' do
36
- it 'fails silently' do
37
- lambda { Dotenv::Environment.new('.env_does_not_exist') }.should_not raise_error
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
38
62
  end
39
63
  end
40
64
 
41
- describe 'apply' do
42
- it 'does not effect env' do
43
- dotenv.apply
44
- expect(ENV.keys).to eq(@env_keys)
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
45
79
  end
46
80
  end
81
+
47
82
  end
48
83
 
49
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 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-08-08 00:00:00 Z
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