dotenv 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ tmp
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 - April 15, 2013
4
+
5
+ * Remove deprectated autoloading. Upgrade to 0.6 first and fix any warnings.
6
+
7
+ * Add Dotenv.load! which raises Errno::ENOENT if the file does not exist
8
+
3
9
  ## 0.6.0 - Mar 22, 2013
4
10
 
5
11
  * Add dotenv-rails gem for autoloading in a Rails app
@@ -8,13 +14,13 @@
8
14
 
9
15
  * Support for double quotes
10
16
 
11
- A="some value"
12
- B="with \"escaped\" quotes"
13
- C="and newline\n expansion"
17
+ A="some value"
18
+ B="with \"escaped\" quotes"
19
+ C="and newline\n expansion"
14
20
 
15
21
  * Support for pow-style variables prefixed with export
16
22
 
17
- export VARIABLE="some value"
23
+ export VARIABLE="some value"
18
24
 
19
25
  [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.5.0...v0.6.0)
20
26
 
data/Rakefile CHANGED
@@ -1,16 +1,24 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
3
  require 'bundler/gem_helper'
4
- %w(dotenv dotenv-rails).each do |name|
5
- namespace name do
6
- Bundler::GemHelper.install_tasks :name => name
4
+
5
+ namespace 'dotenv' do
6
+ Bundler::GemHelper.install_tasks :name => 'dotenv'
7
+ end
8
+
9
+ namespace 'dotenv-rails' do
10
+ class DotenvRailsGemHelper < Bundler::GemHelper
11
+ def guard_already_tagged; end # noop
12
+ def tag_version; end # noop
7
13
  end
8
14
 
9
- task :build => "#{name}:build"
10
- task :install => "#{name}:install"
11
- task :release => "#{name}:release"
15
+ DotenvRailsGemHelper.install_tasks :name => 'dotenv-rails'
12
16
  end
13
17
 
18
+ task :build => ["dotenv:build", 'dotenv-rails:build']
19
+ task :install => ["dotenv:install", 'dotenv-rails:install']
20
+ task :release => ["dotenv:release", 'dotenv-rails:release']
21
+
14
22
  require 'rspec/core/rake_task'
15
23
 
16
24
  desc "Run all specs"
data/lib/dotenv-rails.rb CHANGED
@@ -1,2 +1 @@
1
1
  require 'dotenv/railtie'
2
- Dotenv::Railtie.no_warn!
data/lib/dotenv.rb CHANGED
@@ -2,12 +2,22 @@ require 'dotenv/environment'
2
2
 
3
3
  module Dotenv
4
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
5
+ default_if_empty(filenames).inject({}) do |hash, filename|
6
+ hash.merge(File.exists?(filename) ? Environment.new(filename).apply : {})
8
7
  end
9
8
  end
10
- end
11
9
 
12
- # Deprecated
13
- require 'dotenv/railtie' if defined?(Rails) and defined?(Rails::Railtie)
10
+ # same as `load`, but raises Errno::ENOENT if any files don't exist
11
+ def self.load!(*filenames)
12
+ load(
13
+ *default_if_empty(filenames).each do |filename|
14
+ raise(Errno::ENOENT.new(filename)) unless File.exists?(filename)
15
+ end
16
+ )
17
+ end
18
+
19
+ protected
20
+ def self.default_if_empty(filenames)
21
+ filenames.empty? ? (filenames << '.env') : filenames
22
+ end
23
+ end
@@ -2,7 +2,7 @@ module Dotenv
2
2
  class Environment < Hash
3
3
  def initialize(filename)
4
4
  @filename = filename
5
- load if File.exists? @filename
5
+ load
6
6
  end
7
7
 
8
8
  def load
@@ -10,25 +10,6 @@ module Dotenv
10
10
  Dotenv.load ".env.#{Rails.env}", '.env'
11
11
  end
12
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
32
13
  end
33
14
  end
34
15
 
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -8,6 +8,12 @@ describe Dotenv::Environment do
8
8
  expect(subject['OPTION_A']).to eq('1')
9
9
  expect(subject['OPTION_B']).to eq('2')
10
10
  end
11
+
12
+ it 'fails if file does not exist' do
13
+ expect {
14
+ Dotenv::Environment.new('.does_not_exists')
15
+ }.to raise_error(Errno::ENOENT)
16
+ end
11
17
  end
12
18
 
13
19
  describe 'apply' do
@@ -21,15 +27,6 @@ describe Dotenv::Environment do
21
27
  subject.apply
22
28
  expect(ENV['OPTION_A']).to eq('predefined')
23
29
  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
30
  end
34
31
 
35
32
  it 'parses unquoted values' do
data/spec/dotenv_spec.rb CHANGED
@@ -1,26 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dotenv do
4
- let(:env_path) { fixture_path('plain.env') }
5
-
6
- describe 'load' do
4
+ shared_examples 'load' do
7
5
  context 'with no args' do
6
+ let(:env_files) { [] }
7
+
8
8
  it 'defaults to .env' do
9
9
  Dotenv::Environment.should_receive(:new).with('.env').
10
10
  and_return(mock(:apply => {}))
11
- Dotenv.load
11
+ subject
12
12
  end
13
13
  end
14
14
 
15
15
  context 'with multiple files' do
16
+ let(:env_files) { ['.env', fixture_path('plain.env')] }
17
+
16
18
  let(:expected) do
17
19
  {'OPTION_A' => '1', 'OPTION_B' => '2', 'DOTENV' => 'true'}
18
20
  end
19
21
 
20
- subject do
21
- Dotenv.load('.env', env_path)
22
- end
23
-
24
22
  it 'loads all files' do
25
23
  subject
26
24
  expected.each do |key, value|
@@ -34,6 +32,39 @@ describe Dotenv do
34
32
  end
35
33
  end
36
34
 
35
+ describe 'load' do
36
+ subject { Dotenv.load(*env_files) }
37
+
38
+ it_behaves_like 'load'
39
+
40
+ context 'when the file does not exist' do
41
+ let(:env_files) { ['.env_does_not_exist'] }
42
+
43
+ it 'fails silently' do
44
+ expect { subject }.not_to raise_error
45
+ expect(ENV.keys).to eq(@env_keys)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'load!' do
51
+ subject { Dotenv.load!(*env_files) }
52
+
53
+ it_behaves_like 'load'
54
+
55
+ context 'when one file exists and one does not' do
56
+ let(:env_files) { ['.env', '.env_does_not_exist'] }
57
+
58
+ it 'raises an Errno::ENOENT error and does not load any files' do
59
+ expect do
60
+ expect do
61
+ subject
62
+ end.to raise_error(Errno::ENOENT)
63
+ end.to_not change { ENV.keys }
64
+ end
65
+ end
66
+ end
67
+
37
68
  def fixture_path(name)
38
69
  File.join(File.expand_path('../fixtures', __FILE__), name)
39
70
  end
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.6.0
4
+ version: 0.7.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-03-22 00:00:00.000000000 Z
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake