dotenv 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +2 -2
- data/Changelog.md +14 -0
- data/README.md +20 -5
- data/lib/dotenv.rb +2 -0
- data/lib/dotenv/capistrano.rb +5 -0
- data/lib/dotenv/capistrano/recipes.rb +10 -0
- data/lib/dotenv/environment.rb +25 -9
- data/lib/dotenv/format_error.rb +4 -0
- data/lib/dotenv/railtie.rb +0 -2
- data/lib/dotenv/version.rb +1 -1
- data/spec/dotenv/environment_spec.rb +45 -7
- data/spec/dotenv_spec.rb +23 -2
- data/spec/fixtures/plain.env +3 -0
- metadata +9 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OGMzMjQ2MDFjM2IyMDFiOGVmYzU3ZmJjNWZhYmRlNTFlYWU1MTVjYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzIwNjhlMGQ3NGFlNWQxMTQzMDM1MDRiNjAwMTQ4Y2UzOTFhMDBjNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDQ1MzM1YTlhMGVmYjgyYTc3ZDY1ZDExMjY3NTRkNzhjMmNhMmY0OWViNTVj
|
10
|
+
YmRkMWZlNTJlMDMyOGEwMDdkNjg2OTJjZTA2MmFlMzRjMzY5ZmQ5M2QwMjdj
|
11
|
+
MGQ5NDdlMDNmY2M4ZWZhMGNjNGYxZDc3YmUzYTMwOWRmZWMzYzE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDVjZGMyMWJmYmNkZmYyZDE0YWZiNTc2YzllMzc4OTcyZDk5MjM2ZDE4YWJh
|
14
|
+
YjhiZTZlZDJlYzAwMGEzYzMzMDhkZmMzZDMzMDkwNzNkN2E3OGEyMjMxZDE0
|
15
|
+
MzUzZjRjMDlmZGY0MTlhMWY5MDJmOTE3ZDVmNGI4NDJiZjI0NzA=
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.8.0 - June 12, 2013
|
4
|
+
|
5
|
+
* Added a capistrano recipe to symlink in `.env` on deploy.
|
6
|
+
|
7
|
+
* Allow inline comments
|
8
|
+
|
9
|
+
VARIABLE=value # this is a comment
|
10
|
+
|
11
|
+
* Raises Dotenv::FormatError when parsing fails
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.7.0...v0.8.0)
|
14
|
+
|
3
15
|
## 0.7.0 - April 15, 2013
|
4
16
|
|
5
17
|
* Remove deprectated autoloading. Upgrade to 0.6 first and fix any warnings.
|
6
18
|
|
7
19
|
* Add Dotenv.load! which raises Errno::ENOENT if the file does not exist
|
8
20
|
|
21
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.6.0...v0.7.0)
|
22
|
+
|
9
23
|
## 0.6.0 - Mar 22, 2013
|
10
24
|
|
11
25
|
* Add dotenv-rails gem for autoloading in a Rails app
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png)](https://travis-ci.org/bkeepers/dotenv)
|
2
2
|
|
3
|
-
|
3
|
+
Dotenv loads environment variables from `.env` into `ENV`.
|
4
4
|
|
5
|
-
|
5
|
+
Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
|
6
|
+
|
7
|
+
But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a `.env` file into ENV when the environment is bootstrapped.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -43,15 +45,14 @@ end
|
|
43
45
|
|
44
46
|
## Usage
|
45
47
|
|
46
|
-
Add your application configuration to your `.env` file in the root of
|
47
|
-
your project:
|
48
|
+
Add your application configuration to your `.env` file in the root of your project:
|
48
49
|
|
49
50
|
```shell
|
50
51
|
S3_BUCKET=YOURS3BUCKET
|
51
52
|
SECRET_KEY=YOURSECRETKEYGOESHERE
|
52
53
|
```
|
53
54
|
|
54
|
-
You can also create files per environment, such as `.env.test
|
55
|
+
You can also create files per environment, such as `.env.test`.
|
55
56
|
|
56
57
|
```shell
|
57
58
|
S3_BUCKET=tests3bucket
|
@@ -71,6 +72,20 @@ Whenever your application loads, these variables will be available in `ENV`:
|
|
71
72
|
config.fog_directory = ENV['S3_BUCKET']
|
72
73
|
```
|
73
74
|
|
75
|
+
## Capistrano integration
|
76
|
+
|
77
|
+
In your `config/deploy.rb` file:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
require "dotenv/capistrano"
|
81
|
+
```
|
82
|
+
|
83
|
+
It will symlink the `.env` located in `/path/to/shared` in the new release.
|
84
|
+
|
85
|
+
## Should I commit my .env file?
|
86
|
+
|
87
|
+
It is recommended that you store development-only settings in your `.env` file, and commit it to your repository. Make sure that all your credentials for your development environment are different from your other deployments. This makes it easy for other developers to get started on your project, without compromising your credentials for other environments.
|
88
|
+
|
74
89
|
## Contributing
|
75
90
|
|
76
91
|
1. Fork it
|
data/lib/dotenv.rb
CHANGED
@@ -3,6 +3,7 @@ require 'dotenv/environment'
|
|
3
3
|
module Dotenv
|
4
4
|
def self.load(*filenames)
|
5
5
|
default_if_empty(filenames).inject({}) do |hash, filename|
|
6
|
+
filename = File.expand_path filename
|
6
7
|
hash.merge(File.exists?(filename) ? Environment.new(filename).apply : {})
|
7
8
|
end
|
8
9
|
end
|
@@ -11,6 +12,7 @@ module Dotenv
|
|
11
12
|
def self.load!(*filenames)
|
12
13
|
load(
|
13
14
|
*default_if_empty(filenames).each do |filename|
|
15
|
+
filename = File.expand_path filename
|
14
16
|
raise(Errno::ENOENT.new(filename)) unless File.exists?(filename)
|
15
17
|
end
|
16
18
|
)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
_cset(:dotenv_path){ "#{shared_path}/.env" }
|
3
|
+
|
4
|
+
namespace :dotenv do
|
5
|
+
desc "Symlink shared .env to current release"
|
6
|
+
task :symlink, roles: :app do
|
7
|
+
run "ln -nfs #{dotenv_path} #{release_path}/.env"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/dotenv/environment.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
+
require 'dotenv/format_error'
|
2
|
+
|
1
3
|
module Dotenv
|
2
4
|
class Environment < Hash
|
5
|
+
LINE = /
|
6
|
+
\A
|
7
|
+
(?:export\s+)? # optional export
|
8
|
+
([\w\.]+) # key
|
9
|
+
(?:\s*=\s*|:\s+?) # separator
|
10
|
+
( # value begin
|
11
|
+
'(?:\'|[^'])*' # single quoted value
|
12
|
+
| # or
|
13
|
+
"(?:\"|[^"])*" # double quoted value
|
14
|
+
| # or
|
15
|
+
[^#\n]+ # unquoted value
|
16
|
+
) # value end
|
17
|
+
(?:\s*\#.*)? # optional comment
|
18
|
+
\z
|
19
|
+
/x
|
20
|
+
|
3
21
|
def initialize(filename)
|
4
22
|
@filename = filename
|
5
23
|
load
|
@@ -7,15 +25,13 @@ module Dotenv
|
|
7
25
|
|
8
26
|
def load
|
9
27
|
read.each do |line|
|
10
|
-
if
|
11
|
-
key =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
else self[key] = val
|
18
|
-
end
|
28
|
+
if match = line.match(LINE)
|
29
|
+
key, value = match.captures
|
30
|
+
value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2')
|
31
|
+
value = value.gsub('\n', "\n").gsub(/\\(.)/, '\1') if $1 == '"'
|
32
|
+
self[key] = value
|
33
|
+
elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line
|
34
|
+
raise FormatError, "Line #{line.inspect} doesn't match format"
|
19
35
|
end
|
20
36
|
end
|
21
37
|
end
|
data/lib/dotenv/railtie.rb
CHANGED
data/lib/dotenv/version.rb
CHANGED
@@ -30,31 +30,69 @@ describe Dotenv::Environment do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'parses unquoted values' do
|
33
|
-
expect(env('FOO=bar')).to eql(
|
33
|
+
expect(env('FOO=bar')).to eql('FOO' => 'bar')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'parses values with spaces around equal sign' do
|
37
|
+
expect(env("FOO =bar")).to eql('FOO' => 'bar')
|
38
|
+
expect(env("FOO= bar")).to eql('FOO' => 'bar')
|
34
39
|
end
|
35
40
|
|
36
41
|
it 'parses double quoted values' do
|
37
|
-
expect(env('FOO="bar"')).to eql(
|
42
|
+
expect(env('FOO="bar"')).to eql('FOO' => 'bar')
|
38
43
|
end
|
39
44
|
|
40
45
|
it 'parses single quoted values' do
|
41
|
-
expect(env("FOO='bar'")).to eql(
|
46
|
+
expect(env("FOO='bar'")).to eql('FOO' => 'bar')
|
42
47
|
end
|
43
48
|
|
44
49
|
it 'parses escaped double quotes' do
|
45
|
-
expect(env('FOO="escaped\"bar"')).to eql(
|
50
|
+
expect(env('FOO="escaped\"bar"')).to eql('FOO' => 'escaped"bar')
|
46
51
|
end
|
47
52
|
|
48
53
|
it 'parses yaml style options' do
|
49
|
-
expect(env(
|
54
|
+
expect(env('OPTION_A: 1')).to eql('OPTION_A' => '1')
|
50
55
|
end
|
51
56
|
|
52
57
|
it 'parses export keyword' do
|
53
|
-
expect(env(
|
58
|
+
expect(env('export OPTION_A=2')).to eql('OPTION_A' => '2')
|
54
59
|
end
|
55
60
|
|
56
61
|
it 'expands newlines in quoted strings' do
|
57
|
-
expect(env('FOO="bar\nbaz"')).to eql(
|
62
|
+
expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'parses varibales with "." in the name' do
|
66
|
+
expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'strips unquoted values' do
|
70
|
+
expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar '
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'throws an error if line format is incorrect' do
|
74
|
+
expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'ignores empty lines' do
|
78
|
+
expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'ignores inline comments' do
|
82
|
+
expect(env("foo=bar # this is foo")).to eql('foo' => 'bar')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'allows # in quoted value' do
|
86
|
+
expect(env('foo="bar#baz" # comment')).to eql('foo' => 'bar#baz')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'ignores comment lines' do
|
90
|
+
expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'parses # in quoted values' do
|
94
|
+
expect(env('foo="ba#r"')).to eql('foo' => 'ba#r')
|
95
|
+
expect(env("foo='ba#r'")).to eql('foo' => 'ba#r')
|
58
96
|
end
|
59
97
|
|
60
98
|
require 'tempfile'
|
data/spec/dotenv_spec.rb
CHANGED
@@ -6,7 +6,19 @@ describe Dotenv do
|
|
6
6
|
let(:env_files) { [] }
|
7
7
|
|
8
8
|
it 'defaults to .env' do
|
9
|
-
Dotenv::Environment.should_receive(:new).with('.env').
|
9
|
+
Dotenv::Environment.should_receive(:new).with(expand('.env')).
|
10
|
+
and_return(mock(: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
|
+
File.stub(:exists?){ |arg| arg == expected }
|
21
|
+
Dotenv::Environment.should_receive(:new).with(expected).
|
10
22
|
and_return(mock(:apply => {}))
|
11
23
|
subject
|
12
24
|
end
|
@@ -16,7 +28,12 @@ describe Dotenv do
|
|
16
28
|
let(:env_files) { ['.env', fixture_path('plain.env')] }
|
17
29
|
|
18
30
|
let(:expected) do
|
19
|
-
{'OPTION_A' => '1',
|
31
|
+
{ 'OPTION_A' => '1',
|
32
|
+
'OPTION_B' => '2',
|
33
|
+
'OPTION_C' => '3',
|
34
|
+
'OPTION_D' => '4',
|
35
|
+
'OPTION_E' => '5',
|
36
|
+
'DOTENV' => 'true' }
|
20
37
|
end
|
21
38
|
|
22
39
|
it 'loads all files' do
|
@@ -68,4 +85,8 @@ describe Dotenv do
|
|
68
85
|
def fixture_path(name)
|
69
86
|
File.join(File.expand_path('../fixtures', __FILE__), name)
|
70
87
|
end
|
88
|
+
|
89
|
+
def expand(path)
|
90
|
+
File.expand_path path
|
91
|
+
end
|
71
92
|
end
|
data/spec/fixtures/plain.env
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brandon Keepers
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -63,7 +58,10 @@ files:
|
|
63
58
|
- dotenv.gemspec
|
64
59
|
- lib/dotenv-rails.rb
|
65
60
|
- lib/dotenv.rb
|
61
|
+
- lib/dotenv/capistrano.rb
|
62
|
+
- lib/dotenv/capistrano/recipes.rb
|
66
63
|
- lib/dotenv/environment.rb
|
64
|
+
- lib/dotenv/format_error.rb
|
67
65
|
- lib/dotenv/railtie.rb
|
68
66
|
- lib/dotenv/tasks.rb
|
69
67
|
- lib/dotenv/version.rb
|
@@ -76,27 +74,26 @@ files:
|
|
76
74
|
- spec/spec_helper.rb
|
77
75
|
homepage: https://github.com/bkeepers/dotenv
|
78
76
|
licenses: []
|
77
|
+
metadata: {}
|
79
78
|
post_install_message:
|
80
79
|
rdoc_options: []
|
81
80
|
require_paths:
|
82
81
|
- lib
|
83
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
83
|
requirements:
|
86
84
|
- - ! '>='
|
87
85
|
- !ruby/object:Gem::Version
|
88
86
|
version: '0'
|
89
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
88
|
requirements:
|
92
89
|
- - ! '>='
|
93
90
|
- !ruby/object:Gem::Version
|
94
91
|
version: '0'
|
95
92
|
requirements: []
|
96
93
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
94
|
+
rubygems_version: 2.0.3
|
98
95
|
signing_key:
|
99
|
-
specification_version:
|
96
|
+
specification_version: 4
|
100
97
|
summary: Loads environment variables from `.env`.
|
101
98
|
test_files:
|
102
99
|
- spec/dotenv/environment_spec.rb
|
@@ -106,3 +103,4 @@ test_files:
|
|
106
103
|
- spec/fixtures/quoted.env
|
107
104
|
- spec/fixtures/yaml.env
|
108
105
|
- spec/spec_helper.rb
|
106
|
+
has_rdoc:
|