dotenv 1.0.2 → 2.0.0.beta
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.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/bin/dotenv +2 -9
- data/lib/dotenv.rb +32 -7
- data/lib/dotenv/cli.rb +31 -0
- data/lib/dotenv/environment.rb +1 -0
- data/lib/dotenv/parser.rb +3 -0
- data/lib/dotenv/version.rb +1 -1
- metadata +6 -29
- data/.env +0 -1
- data/.gitignore +0 -8
- data/.travis.yml +0 -9
- data/Changelog.md +0 -142
- data/Gemfile +0 -15
- data/Guardfile +0 -9
- data/Rakefile +0 -30
- data/dotenv.gemspec +0 -21
- data/spec/dotenv/environment_spec.rb +0 -54
- data/spec/dotenv/parser_spec.rb +0 -133
- data/spec/dotenv_spec.rb +0 -102
- data/spec/fixtures/exported.env +0 -2
- data/spec/fixtures/plain.env +0 -5
- data/spec/fixtures/quoted.env +0 -8
- data/spec/fixtures/yaml.env +0 -4
- data/spec/spec_helper.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 082cf9f284dde0511d6c31a21bd1b7f93b9804c3
|
4
|
+
data.tar.gz: bcacb89f7cbf92eea2a2e12764db45a64c7909b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79fd1380227329afe5da7c1d2291e297106ba9f54cab22b204068e035f029bee4bec34289f424d70d3bfa92ce81f772b2632a4a5c1328b1ddd7e3e3938fcc290
|
7
|
+
data.tar.gz: bb84a49f6a65088eec50233de800118fea98de0eb097c63b88ada013d474375b1565548570982254866e93ac836ec25df9bf3a1884d4f866cd7355862954eb1d
|
data/README.md
CHANGED
@@ -6,8 +6,6 @@ Storing [configuration in the environment](http://www.12factor.net/config) is on
|
|
6
6
|
|
7
7
|
But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
|
8
8
|
|
9
|
-
dotenv is intended to be used in development. If you would like to use it in production or other environments, see [dotenv-deployment](https://github.com/bkeepers/dotenv-deployment)
|
10
|
-
|
11
9
|
## Installation
|
12
10
|
|
13
11
|
### Rails
|
@@ -103,6 +101,14 @@ Whenever your application loads, these variables will be available in `ENV`:
|
|
103
101
|
config.fog_directory = ENV['S3_BUCKET']
|
104
102
|
```
|
105
103
|
|
104
|
+
## Multiple Rails Environments
|
105
|
+
|
106
|
+
dotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments environments—such as `/etc/environment` managed by [Puppet](https://github.com/puppetlabs/puppet) or [Chef](https://github.com/opscode/chef), `heroku config`, etc.
|
107
|
+
|
108
|
+
However, some find dotenv to be a convenient way to configure Rails applications in staging and production environments, and you can do that by defining environment-specific files like `.env.production` or `.env.test`.
|
109
|
+
|
110
|
+
You can also `.env.local` for local overrides.
|
111
|
+
|
106
112
|
## Should I commit my .env file?
|
107
113
|
|
108
114
|
Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.
|
data/bin/dotenv
CHANGED
data/lib/dotenv.rb
CHANGED
@@ -2,24 +2,41 @@ require 'dotenv/parser'
|
|
2
2
|
require 'dotenv/environment'
|
3
3
|
|
4
4
|
module Dotenv
|
5
|
-
|
6
|
-
|
5
|
+
extend self
|
6
|
+
|
7
|
+
attr_accessor :instrumenter
|
8
|
+
|
9
|
+
def load(*filenames)
|
10
|
+
with(*filenames) do |f|
|
11
|
+
if File.exist?(f)
|
12
|
+
env = Environment.new(f)
|
13
|
+
instrument('dotenv.load', :env => env) { env.apply }
|
14
|
+
end
|
15
|
+
end
|
7
16
|
end
|
8
17
|
|
9
18
|
# same as `load`, but raises Errno::ENOENT if any files don't exist
|
10
|
-
def
|
11
|
-
with(*filenames)
|
19
|
+
def load!(*filenames)
|
20
|
+
with(*filenames) do |f|
|
21
|
+
env = Environment.new(f)
|
22
|
+
instrument('dotenv.load', :env => env) { env.apply }
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
# same as `load`, but will override existing values in `ENV`
|
15
|
-
def
|
16
|
-
with(*filenames)
|
27
|
+
def overload(*filenames)
|
28
|
+
with(*filenames) do |f|
|
29
|
+
if File.exist?(f)
|
30
|
+
env = Environment.new(f)
|
31
|
+
instrument('dotenv.overload', :env => env) { env.apply! }
|
32
|
+
end
|
33
|
+
end
|
17
34
|
end
|
18
35
|
|
19
36
|
# Internal: Helper to expand list of filenames.
|
20
37
|
#
|
21
38
|
# Returns a hash of all the loaded environment variables.
|
22
|
-
def
|
39
|
+
def with(*filenames, &block)
|
23
40
|
filenames << '.env' if filenames.empty?
|
24
41
|
|
25
42
|
{}.tap do |hash|
|
@@ -28,4 +45,12 @@ module Dotenv
|
|
28
45
|
end
|
29
46
|
end
|
30
47
|
end
|
48
|
+
|
49
|
+
def instrument(name, payload = {}, &block)
|
50
|
+
if instrumenter
|
51
|
+
instrumenter.instrument(name, payload, &block)
|
52
|
+
else
|
53
|
+
block.call
|
54
|
+
end
|
55
|
+
end
|
31
56
|
end
|
data/lib/dotenv/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
|
3
|
+
module Dotenv
|
4
|
+
class CLI
|
5
|
+
attr_reader :argv
|
6
|
+
|
7
|
+
def initialize(argv = [])
|
8
|
+
@argv = argv.dup
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
filenames = if pos = argv.index('-f')
|
13
|
+
# drop the -f
|
14
|
+
argv.delete_at pos
|
15
|
+
# parse one or more comma-separated .env files
|
16
|
+
require 'csv'
|
17
|
+
CSV.parse_line argv.delete_at(pos)
|
18
|
+
else
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
Dotenv.load! *filenames
|
24
|
+
rescue Errno::ENOENT => e
|
25
|
+
abort e.message
|
26
|
+
else
|
27
|
+
exec *argv unless argv.empty?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/dotenv/environment.rb
CHANGED
data/lib/dotenv/parser.rb
CHANGED
@@ -55,6 +55,9 @@ module Dotenv
|
|
55
55
|
end
|
56
56
|
|
57
57
|
hash[key] = value
|
58
|
+
elsif line.split.first == 'export'
|
59
|
+
# looks like you want to export after declaration, I guess that is ok
|
60
|
+
raise FormatError, "Line #{line.inspect} has a variable that is not set" unless line.split[1..-1].all?{ |var| hash.member?(var) }
|
58
61
|
elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line
|
59
62
|
raise FormatError, "Line #{line.inspect} doesn't match format"
|
60
63
|
end
|
data/lib/dotenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -46,32 +46,17 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- ".env"
|
50
|
-
- ".gitignore"
|
51
|
-
- ".travis.yml"
|
52
|
-
- Changelog.md
|
53
|
-
- Gemfile
|
54
|
-
- Guardfile
|
55
49
|
- LICENSE
|
56
50
|
- README.md
|
57
|
-
- Rakefile
|
58
51
|
- bin/dotenv
|
59
|
-
- dotenv.gemspec
|
60
52
|
- lib/dotenv.rb
|
53
|
+
- lib/dotenv/cli.rb
|
61
54
|
- lib/dotenv/environment.rb
|
62
55
|
- lib/dotenv/parser.rb
|
63
56
|
- lib/dotenv/substitutions/command.rb
|
64
57
|
- lib/dotenv/substitutions/variable.rb
|
65
58
|
- lib/dotenv/tasks.rb
|
66
59
|
- lib/dotenv/version.rb
|
67
|
-
- spec/dotenv/environment_spec.rb
|
68
|
-
- spec/dotenv/parser_spec.rb
|
69
|
-
- spec/dotenv_spec.rb
|
70
|
-
- spec/fixtures/exported.env
|
71
|
-
- spec/fixtures/plain.env
|
72
|
-
- spec/fixtures/quoted.env
|
73
|
-
- spec/fixtures/yaml.env
|
74
|
-
- spec/spec_helper.rb
|
75
60
|
homepage: https://github.com/bkeepers/dotenv
|
76
61
|
licenses:
|
77
62
|
- MIT
|
@@ -87,21 +72,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
72
|
version: '0'
|
88
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
74
|
requirements:
|
90
|
-
- - "
|
75
|
+
- - ">"
|
91
76
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
77
|
+
version: 1.3.1
|
93
78
|
requirements: []
|
94
79
|
rubyforge_project:
|
95
80
|
rubygems_version: 2.2.2
|
96
81
|
signing_key:
|
97
82
|
specification_version: 4
|
98
83
|
summary: Loads environment variables from `.env`.
|
99
|
-
test_files:
|
100
|
-
- spec/dotenv/environment_spec.rb
|
101
|
-
- spec/dotenv/parser_spec.rb
|
102
|
-
- spec/dotenv_spec.rb
|
103
|
-
- spec/fixtures/exported.env
|
104
|
-
- spec/fixtures/plain.env
|
105
|
-
- spec/fixtures/quoted.env
|
106
|
-
- spec/fixtures/yaml.env
|
107
|
-
- spec/spec_helper.rb
|
84
|
+
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Changelog.md
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
## 1.0.2 - Oct 14, 2014
|
4
|
-
|
5
|
-
* Define `#load` on `Dotenv::Railtie`, which can be called to manually load `dotenv` before Rails has initialized.
|
6
|
-
|
7
|
-
* add `dotenv/rails-now`, which can be required in the `Gemfile` to immidately load dotenv.
|
8
|
-
|
9
|
-
gem 'dotenv-rails', :require => 'dotenv/rails-now'
|
10
|
-
gem 'gem-that-requires-env-variables'
|
11
|
-
|
12
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v1.0.1...v1.0.2)
|
13
|
-
|
14
|
-
## 1.0.1 - Oct 4, 2014
|
15
|
-
|
16
|
-
* Fix load error with Spring when running `rails server` ([#140](https://github.com/bkeepers/dotenv/issues/140))
|
17
|
-
|
18
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v1.0.0...v1.0.1)
|
19
|
-
|
20
|
-
## 1.0.0 - Oct 3, 2014
|
21
|
-
|
22
|
-
* dotenv-rails is now loaded during the `before_configuration` callback, which is fired when the `Application` constant is defined (`class Application < Rails::Application`).
|
23
|
-
|
24
|
-
* Remove deprecated features. Upgrade to 0.11.0 and fix deprecation warnings before upgrading to 1.0.0.
|
25
|
-
|
26
|
-
* Watch .env for changes with Spring in Rails 4 ([#118](https://github.com/bkeepers/dotenv/pull/118))
|
27
|
-
|
28
|
-
* Fix deprecation warnings for `File.exists?` ([#121](https://github.com/bkeepers/dotenv/pull/121/))
|
29
|
-
|
30
|
-
* Use `Rails.root` to find `.env` ([#122](https://github.com/bkeepers/dotenv/pull/122/files))
|
31
|
-
|
32
|
-
* Avoid substitutions inside single quotes ([#124](https://github.com/bkeepers/dotenv/pull/124))
|
33
|
-
|
34
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.1...v1.0.0)
|
35
|
-
|
36
|
-
## 0.11.1 - Apr 22, 2014
|
37
|
-
|
38
|
-
* Depend on dotenv-deployment ~>0.0.2, which fixes issues with 0.0.1
|
39
|
-
|
40
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.0...v0.11.1)
|
41
|
-
|
42
|
-
## 0.11.0 - Apr 21, 2014
|
43
|
-
|
44
|
-
* Extract dotenv-deployment gem. https://github.com/bkeepers/dotenv-deployment
|
45
|
-
|
46
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.10.0...v0.11.0)
|
47
|
-
|
48
|
-
## 0.10.0 - Feb 22, 2014
|
49
|
-
|
50
|
-
* Add support for executing interpolated commands. (Ruby >= 1.9 only)
|
51
|
-
|
52
|
-
HEAD_SHA=$(git rev-parse HEAD)
|
53
|
-
|
54
|
-
* Add `dotenv_role` option in Capistrano.
|
55
|
-
|
56
|
-
set :dotenv_role, [:app, web]
|
57
|
-
|
58
|
-
* Add `Dotenv.overload` to overwrite existing environment values.
|
59
|
-
|
60
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.9.0...v0.10.0)
|
61
|
-
|
62
|
-
## 0.9.0 - Aug 29, 2013
|
63
|
-
|
64
|
-
* Add support for variable expansion.
|
65
|
-
|
66
|
-
HOST="example.com"
|
67
|
-
URL="http://${USER}@${HOST}"
|
68
|
-
ESCAPED_VARIABLE="this is \$NOT replaced"
|
69
|
-
|
70
|
-
* Allow setting variables without a value.
|
71
|
-
|
72
|
-
BLANK=
|
73
|
-
|
74
|
-
* Add `dotenv` executable to load `.env` for other scripts.
|
75
|
-
|
76
|
-
$ dotenv ./script.py
|
77
|
-
|
78
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.8.0...v0.9.0)
|
79
|
-
|
80
|
-
## 0.8.0 - June 12, 2013
|
81
|
-
|
82
|
-
* Added a capistrano recipe to symlink in `.env` on deploy.
|
83
|
-
|
84
|
-
* Allow inline comments
|
85
|
-
|
86
|
-
VARIABLE=value # this is a comment
|
87
|
-
|
88
|
-
* Raises Dotenv::FormatError when parsing fails
|
89
|
-
|
90
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.7.0...v0.8.0)
|
91
|
-
|
92
|
-
## 0.7.0 - April 15, 2013
|
93
|
-
|
94
|
-
* Remove deprectated autoloading. Upgrade to 0.6 first and fix any warnings.
|
95
|
-
|
96
|
-
* Add Dotenv.load! which raises Errno::ENOENT if the file does not exist
|
97
|
-
|
98
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.6.0...v0.7.0)
|
99
|
-
|
100
|
-
## 0.6.0 - Mar 22, 2013
|
101
|
-
|
102
|
-
* Add dotenv-rails gem for autoloading in a Rails app
|
103
|
-
|
104
|
-
* Deprecated autoloading with plain dotenv gem
|
105
|
-
|
106
|
-
* Support for double quotes
|
107
|
-
|
108
|
-
A="some value"
|
109
|
-
B="with \"escaped\" quotes"
|
110
|
-
C="and newline\n expansion"
|
111
|
-
|
112
|
-
* Support for pow-style variables prefixed with export
|
113
|
-
|
114
|
-
export VARIABLE="some value"
|
115
|
-
|
116
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.5.0...v0.6.0)
|
117
|
-
|
118
|
-
## 0.5.0 - Jan 25, 2013
|
119
|
-
|
120
|
-
* Load immediately on require in Rails instead of waiting for initialization
|
121
|
-
|
122
|
-
* Add YAML-style variables
|
123
|
-
|
124
|
-
VARIABLE: some value
|
125
|
-
|
126
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.4.0...v0.5.0)
|
127
|
-
|
128
|
-
## 0.4.0 - Nov 13, 2012
|
129
|
-
|
130
|
-
* Add support for quoted options, e.g.:
|
131
|
-
|
132
|
-
VARIABLE='some value'
|
133
|
-
|
134
|
-
* Fix rake deprecation warnings
|
135
|
-
|
136
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.3.0...v0.4.0)
|
137
|
-
|
138
|
-
## 0.3.0 - Oct 25, 2012
|
139
|
-
|
140
|
-
* Avoid overriding existing ENV variables so values set before loading the app are maintained.
|
141
|
-
|
142
|
-
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.2.0...v0.3.0)
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec :name => 'dotenv'
|
3
|
-
gemspec :name => 'dotenv-rails'
|
4
|
-
|
5
|
-
gem 'dotenv-deployment', :github => 'bkeepers/dotenv-deployment'
|
6
|
-
|
7
|
-
group :guard do
|
8
|
-
gem 'guard-rspec'
|
9
|
-
gem 'guard-bundler'
|
10
|
-
gem 'rb-fsevent'
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :rbx do
|
14
|
-
gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library
|
15
|
-
end
|
data/Guardfile
DELETED
data/Rakefile
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
|
3
|
-
require 'bundler/gem_helper'
|
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
|
13
|
-
end
|
14
|
-
|
15
|
-
DotenvRailsGemHelper.install_tasks :name => 'dotenv-rails'
|
16
|
-
end
|
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
|
-
|
22
|
-
require 'rspec/core/rake_task'
|
23
|
-
|
24
|
-
desc "Run all specs"
|
25
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
26
|
-
t.rspec_opts = %w[--color]
|
27
|
-
t.verbose = false
|
28
|
-
end
|
29
|
-
|
30
|
-
task :default => :spec
|
data/dotenv.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
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{Loads environment variables from `.env`.}
|
9
|
-
gem.summary = %q{Loads environment variables from `.env`.}
|
10
|
-
gem.homepage = "https://github.com/bkeepers/dotenv"
|
11
|
-
gem.license = 'MIT'
|
12
|
-
|
13
|
-
gem.files = `git ls-files | grep -v rails`.split($\)
|
14
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
-
gem.name = "dotenv"
|
17
|
-
gem.require_paths = ["lib"]
|
18
|
-
|
19
|
-
gem.add_development_dependency 'rake'
|
20
|
-
gem.add_development_dependency 'rspec'
|
21
|
-
end
|
@@ -1,54 +0,0 @@
|
|
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
|
-
|
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
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'apply' do
|
20
|
-
it 'sets variables in ENV' do
|
21
|
-
subject.apply
|
22
|
-
expect(ENV['OPTION_A']).to eq('1')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'does not override defined variables' do
|
26
|
-
ENV['OPTION_A'] = 'predefined'
|
27
|
-
subject.apply
|
28
|
-
expect(ENV['OPTION_A']).to eq('predefined')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'apply!' do
|
33
|
-
it 'sets variables in the ENV' do
|
34
|
-
subject.apply!
|
35
|
-
expect(ENV['OPTION_A']).to eq('1')
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'overrides defined variables' do
|
39
|
-
ENV['OPTION_A'] = 'predefined'
|
40
|
-
subject.apply!
|
41
|
-
expect(ENV['OPTION_A']).to eq('1')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
require 'tempfile'
|
46
|
-
def env(text)
|
47
|
-
file = Tempfile.new('dotenv')
|
48
|
-
file.write text
|
49
|
-
file.close
|
50
|
-
env = Dotenv::Environment.new(file.path)
|
51
|
-
file.unlink
|
52
|
-
env
|
53
|
-
end
|
54
|
-
end
|
data/spec/dotenv/parser_spec.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dotenv::Parser do
|
4
|
-
def env(string)
|
5
|
-
Dotenv::Parser.call(string)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'parses unquoted values' do
|
9
|
-
expect(env('FOO=bar')).to eql('FOO' => 'bar')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'parses values with spaces around equal sign' do
|
13
|
-
expect(env("FOO =bar")).to eql('FOO' => 'bar')
|
14
|
-
expect(env("FOO= bar")).to eql('FOO' => 'bar')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'parses double quoted values' do
|
18
|
-
expect(env('FOO="bar"')).to eql('FOO' => 'bar')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'parses single quoted values' do
|
22
|
-
expect(env("FOO='bar'")).to eql('FOO' => 'bar')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'parses escaped double quotes' do
|
26
|
-
expect(env('FOO="escaped\"bar"')).to eql('FOO' => 'escaped"bar')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'parses empty values' do
|
30
|
-
expect(env('FOO=')).to eql('FOO' => '')
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'expands variables found in values' do
|
34
|
-
expect(env("FOO=test\nBAR=$FOO")).to eql('FOO' => 'test', 'BAR' => 'test')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'parses variables wrapped in brackets' do
|
38
|
-
expect(env("FOO=test\nBAR=${FOO}bar")).to eql('FOO' => 'test', 'BAR' => 'testbar')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'reads variables from ENV when expanding if not found in local env' do
|
42
|
-
ENV['FOO'] = 'test'
|
43
|
-
expect(env('BAR=$FOO')).to eql('BAR' => 'test')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'expands undefined variables to an empty string' do
|
47
|
-
expect(env('BAR=$FOO')).to eql('BAR' => '')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'expands variables in double quoted strings' do
|
51
|
-
expect(env("FOO=test\nBAR=\"quote $FOO\"")).to eql('FOO' => 'test', 'BAR' => 'quote test')
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'does not expand variables in single quoted strings' do
|
55
|
-
expect(env("BAR='quote $FOO'")).to eql('BAR' => 'quote $FOO')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'does not expand escaped variables' do
|
59
|
-
expect(env('FOO="foo\$BAR"')).to eql('FOO' => 'foo$BAR')
|
60
|
-
expect(env('FOO="foo\${BAR}"')).to eql('FOO' => 'foo${BAR}')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'parses yaml style options' do
|
64
|
-
expect(env('OPTION_A: 1')).to eql('OPTION_A' => '1')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'parses export keyword' do
|
68
|
-
expect(env('export OPTION_A=2')).to eql('OPTION_A' => '2')
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'expands newlines in quoted strings' do
|
72
|
-
expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'parses variables with "." in the name' do
|
76
|
-
expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'strips unquoted values' do
|
80
|
-
expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'throws an error if line format is incorrect' do
|
84
|
-
expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'ignores empty lines' do
|
88
|
-
expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'ignores inline comments' do
|
92
|
-
expect(env("foo=bar # this is foo")).to eql('foo' => 'bar')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'allows # in quoted value' do
|
96
|
-
expect(env('foo="bar#baz" # comment')).to eql('foo' => 'bar#baz')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'ignores comment lines' do
|
100
|
-
expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'parses # in quoted values' do
|
104
|
-
expect(env('foo="ba#r"')).to eql('foo' => 'ba#r')
|
105
|
-
expect(env("foo='ba#r'")).to eql('foo' => 'ba#r')
|
106
|
-
end
|
107
|
-
|
108
|
-
if RUBY_VERSION > '1.8.7'
|
109
|
-
it 'parses shell commands interpolated in $()' do
|
110
|
-
expect(env('ruby_v=$(ruby -v)')).to eql('ruby_v' => RUBY_DESCRIPTION)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'allows balanced parentheses within interpolated shell commands' do
|
114
|
-
expect(env('ruby_v=$(echo "$(echo "$(echo "$(ruby -v)")")")')).to eql('ruby_v' => RUBY_DESCRIPTION)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "doesn't interpolate shell commands when escape says not to" do
|
118
|
-
expect(env('ruby_v=escaped-\$(ruby -v)')).to eql('ruby_v' => 'escaped-$(ruby -v)')
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'is not thrown off by quotes in interpolated shell commands' do
|
122
|
-
expect(env('interp=$(echo "Quotes won\'t be a problem")')['interp']).to eql("Quotes won't be a problem")
|
123
|
-
end
|
124
|
-
|
125
|
-
# This functionality is not supported on JRuby or Rubinius
|
126
|
-
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby') && !defined?(Rubinius)
|
127
|
-
it 'substitutes shell variables within interpolated shell commands' do
|
128
|
-
expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))['interp']).to eql("VAR1 is var1")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
data/spec/dotenv_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dotenv do
|
4
|
-
shared_examples 'load' do
|
5
|
-
context 'with no args' do
|
6
|
-
let(:env_files) { [] }
|
7
|
-
|
8
|
-
it 'defaults to .env' do
|
9
|
-
expect(Dotenv::Environment).to receive(:new).with(expand('.env')).
|
10
|
-
and_return(double(:apply => {}, :apply! => {}))
|
11
|
-
subject
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with a tilde path' do
|
16
|
-
let(:env_files) { ['~/.env'] }
|
17
|
-
|
18
|
-
it 'expands the path' do
|
19
|
-
expected = expand("~/.env")
|
20
|
-
allow(File).to receive(:exist?){ |arg| arg == expected }
|
21
|
-
expect(Dotenv::Environment).to receive(:new).with(expected).
|
22
|
-
and_return(double(:apply => {}, :apply! => {}))
|
23
|
-
subject
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with multiple files' do
|
28
|
-
let(:env_files) { ['.env', fixture_path('plain.env')] }
|
29
|
-
|
30
|
-
let(:expected) do
|
31
|
-
{ 'OPTION_A' => '1',
|
32
|
-
'OPTION_B' => '2',
|
33
|
-
'OPTION_C' => '3',
|
34
|
-
'OPTION_D' => '4',
|
35
|
-
'OPTION_E' => '5',
|
36
|
-
'DOTENV' => 'true' }
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'loads all files' do
|
40
|
-
subject
|
41
|
-
expected.each do |key, value|
|
42
|
-
expect(ENV[key]).to eq(value)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns hash of loaded environments' do
|
47
|
-
expect(subject).to eq(expected)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'load' do
|
53
|
-
subject { Dotenv.load(*env_files) }
|
54
|
-
|
55
|
-
it_behaves_like 'load'
|
56
|
-
|
57
|
-
context 'when the file does not exist' do
|
58
|
-
let(:env_files) { ['.env_does_not_exist'] }
|
59
|
-
|
60
|
-
it 'fails silently' do
|
61
|
-
expect { subject }.not_to raise_error
|
62
|
-
expect(ENV.keys).to eq(@env_keys)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'load!' do
|
68
|
-
subject { Dotenv.load!(*env_files) }
|
69
|
-
|
70
|
-
it_behaves_like 'load'
|
71
|
-
|
72
|
-
context 'when one file exists and one does not' do
|
73
|
-
let(:env_files) { ['.env', '.env_does_not_exist'] }
|
74
|
-
|
75
|
-
it 'raises an Errno::ENOENT error' do
|
76
|
-
expect { subject }.to raise_error(Errno::ENOENT)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'overload' do
|
82
|
-
let(:env_files) { [fixture_path('plain.env')] }
|
83
|
-
subject { Dotenv.overload(*env_files) }
|
84
|
-
it_behaves_like 'load'
|
85
|
-
|
86
|
-
it 'overrides any existing ENV variables' do
|
87
|
-
ENV['OPTION_A'] = 'predefined'
|
88
|
-
|
89
|
-
subject
|
90
|
-
|
91
|
-
expect(ENV['OPTION_A']).to eq('1')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def fixture_path(name)
|
96
|
-
File.join(File.expand_path('../fixtures', __FILE__), name)
|
97
|
-
end
|
98
|
-
|
99
|
-
def expand(path)
|
100
|
-
File.expand_path path
|
101
|
-
end
|
102
|
-
end
|
data/spec/fixtures/exported.env
DELETED
data/spec/fixtures/plain.env
DELETED
data/spec/fixtures/quoted.env
DELETED
data/spec/fixtures/yaml.env
DELETED