dotenv 0.11.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/Changelog.md +16 -0
- data/README.md +15 -6
- data/dotenv.gemspec +0 -2
- data/lib/dotenv-rails.rb +1 -11
- data/lib/dotenv.rb +9 -7
- data/lib/dotenv/parser.rb +4 -2
- data/lib/dotenv/railtie.rb +3 -5
- data/lib/dotenv/substitutions/command.rb +10 -3
- data/lib/dotenv/substitutions/variable.rb +9 -2
- data/lib/dotenv/version.rb +1 -1
- data/spec/dotenv/environment_spec.rb +1 -1
- data/spec/dotenv/parser_spec.rb +6 -2
- data/spec/dotenv_spec.rb +1 -1
- metadata +12 -28
- data/lib/dotenv/capistrano.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db917b64277779cd86a42c05633d8df2fdbfba8f
|
4
|
+
data.tar.gz: d7227f87369b787997dcf0136f468c9a5d333c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce97b5659a92e99839daa9a40f725af09c48eead2a4b03c482099f9d34f7f6b90474245b88b6d1641ee1a1eb8c4765ab11a6153d49dd6ab58e56bc1302f3a18c
|
7
|
+
data.tar.gz: 066064f298e0579f0cfe7e1739b836f26d27226f5358ca1cee49eb33e692b67cf14638186ec03439865990c5a37a69acede5a5da79149e4085747cd6a4500017
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.0.0 - Oct 3, 2014
|
4
|
+
|
5
|
+
* Remove deprecated features. Upgrade to 0.11.0 and fix deprecation warnings before upgrading to 1.0.0.
|
6
|
+
|
7
|
+
* Watch .env for changes with Spring in Rails 4 ([#118](https://github.com/bkeepers/dotenv/pull/118))
|
8
|
+
|
9
|
+
* Fix deprecation warnings for `File.exists?` ([#121](https://github.com/bkeepers/dotenv/pull/121/))
|
10
|
+
|
11
|
+
* Use `Rails.root` to find `.env` ([#122](https://github.com/bkeepers/dotenv/pull/122/files))
|
12
|
+
|
13
|
+
* Avoid substitutions inside single quotes ([#124](https://github.com/bkeepers/dotenv/pull/124))
|
14
|
+
|
15
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.1...v1.0.0)
|
16
|
+
|
3
17
|
## 0.11.1 - Apr 22, 2014
|
4
18
|
|
5
19
|
* Depend on dotenv-deployment ~>0.0.2, which fixes issues with 0.0.1
|
6
20
|
|
21
|
+
[Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.0...v0.11.1)
|
22
|
+
|
7
23
|
## 0.11.0 - Apr 21, 2014
|
8
24
|
|
9
25
|
* Extract dotenv-deployment gem. https://github.com/bkeepers/dotenv-deployment
|
data/README.md
CHANGED
@@ -8,7 +8,6 @@ But it is not always practical to set environment variables on development machi
|
|
8
8
|
|
9
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
10
|
|
11
|
-
|
12
11
|
## Installation
|
13
12
|
|
14
13
|
### Rails
|
@@ -67,11 +66,17 @@ S3_BUCKET=YOURS3BUCKET
|
|
67
66
|
SECRET_KEY=YOURSECRETKEYGOESHERE
|
68
67
|
```
|
69
68
|
|
70
|
-
|
69
|
+
If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
|
70
|
+
|
71
|
+
```shell
|
72
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n"
|
73
|
+
```
|
74
|
+
|
75
|
+
You may also add `export` in front of each line so you can `source` the file in bash:
|
71
76
|
|
72
|
-
```
|
73
|
-
S3_BUCKET
|
74
|
-
SECRET_KEY
|
77
|
+
```shell
|
78
|
+
export S3_BUCKET=YOURS3BUCKET
|
79
|
+
export SECRET_KEY=YOURSECRETKEYGOESHERE
|
75
80
|
```
|
76
81
|
|
77
82
|
Whenever your application loads, these variables will be available in `ENV`:
|
@@ -82,10 +87,14 @@ config.fog_directory = ENV['S3_BUCKET']
|
|
82
87
|
|
83
88
|
## Should I commit my .env file?
|
84
89
|
|
85
|
-
|
90
|
+
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.
|
91
|
+
|
92
|
+
Personally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data.
|
86
93
|
|
87
94
|
## Contributing
|
88
95
|
|
96
|
+
If you want a better idea of how dotenv works, check out the [Ruby Rogues Code Reading of dotenv](https://www.youtube.com/watch?v=lKmY_0uY86s).
|
97
|
+
|
89
98
|
1. Fork it
|
90
99
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
100
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
data/dotenv.gemspec
CHANGED
data/lib/dotenv-rails.rb
CHANGED
@@ -1,11 +1 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
env_file = ".env.#{Rails.env}"
|
4
|
-
if File.exists?(env_file) && !defined?(Dotenv::Deployment)
|
5
|
-
warn "Auto-loading of `#{env_file}` will be removed in 1.0. See " +
|
6
|
-
"https://github.com/bkeepers/dotenv-deployment if you would like to " +
|
7
|
-
"continue using this feature."
|
8
|
-
Dotenv.load ".env.#{Rails.env}"
|
9
|
-
end
|
10
|
-
|
11
|
-
Dotenv.load '.env'
|
1
|
+
require "dotenv/railtie"
|
data/lib/dotenv.rb
CHANGED
@@ -3,7 +3,7 @@ require 'dotenv/environment'
|
|
3
3
|
|
4
4
|
module Dotenv
|
5
5
|
def self.load(*filenames)
|
6
|
-
with(*filenames) { |f| Environment.new(f).apply if File.
|
6
|
+
with(*filenames) { |f| Environment.new(f).apply if File.exist?(f) }
|
7
7
|
end
|
8
8
|
|
9
9
|
# same as `load`, but raises Errno::ENOENT if any files don't exist
|
@@ -13,17 +13,19 @@ module Dotenv
|
|
13
13
|
|
14
14
|
# same as `load`, but will override existing values in `ENV`
|
15
15
|
def self.overload(*filenames)
|
16
|
-
with(*filenames) { |f| Environment.new(f).apply! if File.
|
16
|
+
with(*filenames) { |f| Environment.new(f).apply! if File.exist?(f) }
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# Internal: Helper to expand list of filenames.
|
20
|
+
#
|
21
|
+
# Returns a hash of all the loaded environment variables.
|
21
22
|
def self.with(*filenames, &block)
|
22
23
|
filenames << '.env' if filenames.empty?
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
{}.tap do |hash|
|
26
|
+
filenames.each do |filename|
|
27
|
+
hash.merge! block.call(File.expand_path(filename)) || {}
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/dotenv/parser.rb
CHANGED
@@ -48,8 +48,10 @@ module Dotenv
|
|
48
48
|
value = value.gsub(/\\([^$])/, '\1')
|
49
49
|
end
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
if $1 != "'"
|
52
|
+
@@substitutions.each do |proc|
|
53
|
+
value = proc.call(value, hash)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
hash[key] = value
|
data/lib/dotenv/railtie.rb
CHANGED
@@ -2,11 +2,9 @@ require 'dotenv'
|
|
2
2
|
|
3
3
|
module Dotenv
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
warn "The `dotenv` task is no longer needed and will be removed in 1.0."
|
9
|
-
end
|
5
|
+
config.before_configuration do
|
6
|
+
Dotenv.load Rails.root.join('.env')
|
7
|
+
Spring.watch Rails.root.join('.env') if defined?(Spring)
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module Dotenv
|
2
2
|
module Substitutions
|
3
|
+
# Substitute shell commands in a value.
|
4
|
+
#
|
5
|
+
# SHA=$(git rev-parse HEAD)
|
6
|
+
#
|
3
7
|
module Command
|
4
8
|
class << self
|
5
9
|
|
6
10
|
INTERPOLATED_SHELL_COMMAND = /
|
7
|
-
(?<backslash>\\)?
|
8
|
-
\$
|
11
|
+
(?<backslash>\\)? # is it escaped with a backslash?
|
12
|
+
\$ # literal $
|
9
13
|
(?<cmd> # collect command content for eval
|
10
14
|
\( # require opening paren
|
11
15
|
([^()]|\g<cmd>)+ # allow any number of non-parens, or balanced parens (by nesting the <cmd> expression recursively)
|
@@ -16,11 +20,14 @@ module Dotenv
|
|
16
20
|
def call(value, env)
|
17
21
|
# Process interpolated shell commands
|
18
22
|
value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
|
19
|
-
|
23
|
+
# Eliminate opening and closing parentheses
|
24
|
+
command = $~[:cmd][1..-2]
|
20
25
|
|
21
26
|
if $~[:backslash]
|
27
|
+
# Command is escaped, don't replace it.
|
22
28
|
$~[0][1..-1]
|
23
29
|
else
|
30
|
+
# Execute the command and return the value
|
24
31
|
`#{command}`.chomp
|
25
32
|
end
|
26
33
|
end
|
@@ -1,11 +1,16 @@
|
|
1
1
|
module Dotenv
|
2
2
|
module Substitutions
|
3
|
+
# Substitute variables in a value.
|
4
|
+
#
|
5
|
+
# HOST=example.com
|
6
|
+
# URL="https://$HOST"
|
7
|
+
#
|
3
8
|
module Variable
|
4
9
|
class << self
|
5
10
|
|
6
11
|
VARIABLE = /
|
7
|
-
(\\)?
|
8
|
-
(\$)
|
12
|
+
(\\)? # is it escaped with a backslash?
|
13
|
+
(\$) # literal $
|
9
14
|
( # collect braces with var for sub
|
10
15
|
\{? # allow brace wrapping
|
11
16
|
([A-Z0-9_]+) # match the variable
|
@@ -17,8 +22,10 @@ module Dotenv
|
|
17
22
|
# Process embedded variables
|
18
23
|
value.scan(VARIABLE).each do |parts|
|
19
24
|
if parts.first == '\\'
|
25
|
+
# Variable is escaped, don't replace it.
|
20
26
|
replace = parts[1...-1].join('')
|
21
27
|
else
|
28
|
+
# Replace it with the value from the environment
|
22
29
|
replace = env.fetch(parts.last) { ENV[parts.last] }
|
23
30
|
end
|
24
31
|
|
data/lib/dotenv/version.rb
CHANGED
data/spec/dotenv/parser_spec.rb
CHANGED
@@ -47,8 +47,12 @@ describe Dotenv::Parser do
|
|
47
47
|
expect(env('BAR=$FOO')).to eql('BAR' => '')
|
48
48
|
end
|
49
49
|
|
50
|
-
it 'expands variables in quoted strings' do
|
51
|
-
expect(env("FOO=test\nBAR
|
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')
|
52
56
|
end
|
53
57
|
|
54
58
|
it 'does not expand escaped variables' do
|
data/spec/dotenv_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Dotenv do
|
|
17
17
|
|
18
18
|
it 'expands the path' do
|
19
19
|
expected = expand("~/.env")
|
20
|
-
allow(File).to receive(:
|
20
|
+
allow(File).to receive(:exist?){ |arg| arg == expected }
|
21
21
|
expect(Dotenv::Environment).to receive(:new).with(expected).
|
22
22
|
and_return(double(:apply => {}, :apply! => {}))
|
23
23
|
subject
|
metadata
CHANGED
@@ -1,55 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: dotenv-deployment
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.2
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- -
|
17
|
+
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '0'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- -
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- -
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- -
|
38
|
+
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
description: Loads environment variables from `.env`.
|
@@ -60,9 +46,9 @@ executables:
|
|
60
46
|
extensions: []
|
61
47
|
extra_rdoc_files: []
|
62
48
|
files:
|
63
|
-
- .env
|
64
|
-
- .gitignore
|
65
|
-
- .travis.yml
|
49
|
+
- ".env"
|
50
|
+
- ".gitignore"
|
51
|
+
- ".travis.yml"
|
66
52
|
- Changelog.md
|
67
53
|
- Gemfile
|
68
54
|
- Guardfile
|
@@ -74,7 +60,6 @@ files:
|
|
74
60
|
- dotenv.gemspec
|
75
61
|
- lib/dotenv-rails.rb
|
76
62
|
- lib/dotenv.rb
|
77
|
-
- lib/dotenv/capistrano.rb
|
78
63
|
- lib/dotenv/environment.rb
|
79
64
|
- lib/dotenv/parser.rb
|
80
65
|
- lib/dotenv/railtie.rb
|
@@ -100,17 +85,17 @@ require_paths:
|
|
100
85
|
- lib
|
101
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
87
|
requirements:
|
103
|
-
- -
|
88
|
+
- - ">="
|
104
89
|
- !ruby/object:Gem::Version
|
105
90
|
version: '0'
|
106
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
92
|
requirements:
|
108
|
-
- -
|
93
|
+
- - ">="
|
109
94
|
- !ruby/object:Gem::Version
|
110
95
|
version: '0'
|
111
96
|
requirements: []
|
112
97
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.2.2
|
114
99
|
signing_key:
|
115
100
|
specification_version: 4
|
116
101
|
summary: Loads environment variables from `.env`.
|
@@ -123,4 +108,3 @@ test_files:
|
|
123
108
|
- spec/fixtures/quoted.env
|
124
109
|
- spec/fixtures/yaml.env
|
125
110
|
- spec/spec_helper.rb
|
126
|
-
has_rdoc:
|
data/lib/dotenv/capistrano.rb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
warn "Capistrano support has been moved to the dotenv-deployment gem. Add it " +
|
2
|
-
"to your Gemfile and change the require to 'dotenv/deployment/capistrano'. " +
|
3
|
-
"See https://github.com/bkeepers/dotenv-deployment#capistrano."
|
4
|
-
|
5
|
-
# This will be removed in 1.0
|
6
|
-
require 'dotenv/deployment/capistrano'
|