dotenv-rails 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fda3b4ebc0fdf813b5f05ad06295b43d346546a9
4
- data.tar.gz: 495019f65e82ec32fa3c7df2975b112a70dd81b8
3
+ metadata.gz: 7e3538ec3b2d9ddf456640c6bbc5784de19204b8
4
+ data.tar.gz: 1da62894cf429e9c10bc168478d023f7b84dfcb0
5
5
  SHA512:
6
- metadata.gz: 7279f8f765b5472ce0470448781d087fc2c0360506ff8b89eef20adba5f230fd82d3fe7d56e19d91a72c39af9e08ac3dac6492d03de50225a156f7fdca8c6a86
7
- data.tar.gz: bec6096e0651571fd99cf3c45b0d6ed47db8ef6b090aa49a4c05cb0b487e48ded7c7280ac6768e6a627c634135579a87b042c04a8189c28d543365628d4303cb
6
+ metadata.gz: a8391f94ba1cf3af34a577925094cc1444ade302de874d7bf9573a335e22e3c7dd828e5a89d1b75f48821891de03a00bab66df921a33e9c45d3b0f15110139c8
7
+ data.tar.gz: aa4b640e4f01d91b46bcfb38ad1c8ef312f4c0b1a0af070f7373844676d86fa53f9ed23224583ac6091691563fb3a3b543348bd824ef1e5e7596eba27ebdb41e
data/README.md CHANGED
@@ -15,7 +15,7 @@ But it is not always practical to set environment variables on development machi
15
15
  Add this line to the top of your application's Gemfile:
16
16
 
17
17
  ```ruby
18
- gem 'dotenv-rails', :groups => [:development, :test]
18
+ gem 'dotenv-rails', groups: [:development, :test]
19
19
  ```
20
20
 
21
21
  And then execute:
@@ -40,7 +40,7 @@ HOSTNAME = ENV['HOSTNAME']
40
40
  If you use gems that require environment variables to be set before they are loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and require `dotenv/rails-now`.
41
41
 
42
42
  ```ruby
43
- gem 'dotenv-rails', :require => 'dotenv/rails-now'
43
+ gem 'dotenv-rails', require: 'dotenv/rails-now'
44
44
  gem 'gem-that-requires-env-variables'
45
45
  ```
46
46
 
@@ -80,7 +80,7 @@ To ensure `.env` is loaded in rake, load the tasks:
80
80
  ```ruby
81
81
  require 'dotenv/tasks'
82
82
 
83
- task :mytask => :dotenv do
83
+ task mytask: :dotenv do
84
84
  # things that require .env
85
85
  end
86
86
  ```
@@ -147,22 +147,35 @@ SECRET_KEY=YOURSECRETKEYGOESHERE # comment
147
147
  SECRET_HASH="something-with-a-#-hash"
148
148
  ```
149
149
 
150
- ## Multiple Rails Environments
150
+ ## Frequently Answered Questions
151
+
152
+ ### Can I use dotenv in production?
151
153
 
152
154
  dotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments - such as `/etc/environment` managed by [Puppet](https://github.com/puppetlabs/puppet) or [Chef](https://github.com/chef/chef), `heroku config`, etc.
153
155
 
154
156
  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`.
155
157
 
156
- You can also use `.env.local` for local overrides.
158
+ If you use this gem to handle env vars for multiple Rails environments (development, test, production, etc.), please note that env vars that are general to all environments should be stored in `.env`. Then, environment specific env vars should be stored in `.env.<that environment's name>`.
159
+
160
+ ### What other .env* files can I use?
161
+
162
+ `dotenv-rails` will load the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence:
157
163
 
158
- If you use this gem to handle env vars for multiple Rails environments (development, test, production, etc.), please note that env vars that are general to all environments should be stored in `.env`. Then, environment specific env vars should be stored in `.env.<that environment's name>`. When you load a certain environment, dotenv will first load general env vars from `.env`, then load environment specific env vars from `.env.<current environment>`. Variables defined in `.env.<current environment>` will override any values set in `.env` or already defined in the environment.
164
+ - `.env` - The Original®
165
+ - `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
166
+ - `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`.
167
+ - `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.
159
168
 
160
- ## Should I commit my .env file?
169
+ ### Should I commit my .env file?
161
170
 
162
171
  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.
163
172
 
164
173
  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.
165
174
 
175
+ ### Why is it not overriding existing `ENV` variables?
176
+
177
+ By default, it **won't** overwrite existing environment variables as dotenv assumes the deployment environment has more knowledge about configuration than the application does. To overwrite existing environment variables you can use `Dotenv.overload`.
178
+
166
179
  ## Contributing
167
180
 
168
181
  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).
@@ -2,7 +2,7 @@
2
2
  # loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and
3
3
  # require `dotenv/rails-now`.
4
4
  #
5
- # gem "dotenv-rails", :require => "dotenv/rails-now"
5
+ # gem "dotenv-rails", require: "dotenv/rails-now"
6
6
  # gem "gem-that-requires-env-variables"
7
7
  #
8
8
 
@@ -1,5 +1,18 @@
1
1
  require "dotenv"
2
2
 
3
+ # Fix for rspec rake tasks loading in development
4
+ #
5
+ # Dotenv loads environment variables when the Rails application is initialized.
6
+ # When running `rake`, the Rails application is initialized in development.
7
+ # Rails includes some hacks to set `RAILS_ENV=test` when running `rake test`,
8
+ # but rspec does not include the same hacks.
9
+ #
10
+ # See https://github.com/bkeepers/dotenv/issues/219
11
+ if defined?(Rake.application)
12
+ is_running_specs = Rake.application.top_level_tasks.grep(/^spec(:|$)/).any?
13
+ Rails.env = ENV["RAILS_ENV"] ||= "test" if is_running_specs
14
+ end
15
+
3
16
  Dotenv.instrumenter = ActiveSupport::Notifications
4
17
 
5
18
  # Watch all loaded env files with Spring
@@ -22,11 +35,7 @@ module Dotenv
22
35
  # This will get called during the `before_configuration` callback, but you
23
36
  # can manually call `Dotenv::Railtie.load` if you needed it sooner.
24
37
  def load
25
- Dotenv.load(
26
- root.join(".env.local"),
27
- root.join(".env.#{Rails.env}"),
28
- root.join(".env")
29
- )
38
+ Dotenv.load(*dotenv_files)
30
39
  end
31
40
 
32
41
  # Internal: `Rails.root` is nil in Rails 4.1 before the application is
@@ -43,5 +52,16 @@ module Dotenv
43
52
  end
44
53
 
45
54
  config.before_configuration { load }
55
+
56
+ private
57
+
58
+ def dotenv_files
59
+ [
60
+ root.join(".env.#{Rails.env}.local"),
61
+ (root.join(".env.local") unless Rails.env.test?),
62
+ root.join(".env.#{Rails.env}"),
63
+ root.join(".env")
64
+ ].compact
65
+ end
46
66
  end
47
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.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: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.2
19
+ version: 2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.2
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement