dotenv-rails 1.0.2 → 2.0.0.beta

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: d9b8a2f36a1e82b0bbb76f969ed18daefaa0f53d
4
- data.tar.gz: bb950985d9d6dedd2f49f5921abea128c66042ad
3
+ metadata.gz: ddc13d30ca15fc74ab46b07b46d17887af3714c1
4
+ data.tar.gz: 232c81c2c8ceef4e04e0b6f742eacc78be9adc3a
5
5
  SHA512:
6
- metadata.gz: 54fc237f8118410e5c35dc24ec52efd1153d034e1c6f01e8b61e3b4776e0e08ddf58bd4b4e8066099459bbac9610cbc08fae5f8cb8cd5530a6c4bac217ae654a
7
- data.tar.gz: e81f9732b8e9a8a7000dbefd5f0358d1ea2a6e50c26a3d9c1e3516b6b0ad979876d469f944fab28ec099c6b66cab9229265374cf2bac33b1179b46e9fd898290
6
+ metadata.gz: 85f66b0ff491376129ae227305be458b826097425b987f8f9b60b8af5136a916f078ac2649ecf5328616b94ab341d8409ad13288fd9d2b3059d50abdba42d6a9
7
+ data.tar.gz: beedfaa2f1877e714f7198179530c48fe7e148168f3e09994894840c245d70a69e384e45712e185348bd94f019adf3ace0cd8d07485d2cf56209644b7ae66a19
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Brandon Keepers
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv)
2
+
3
+ Shim to load environment variables from `.env` into `ENV` in *development*.
4
+
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 loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
8
+
9
+ ## Installation
10
+
11
+ ### Rails
12
+
13
+ Add this line to the top of your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'dotenv-rails', :groups => [:development, :test]
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```shell
22
+ $ bundle
23
+ ```
24
+
25
+ #### Note on load order
26
+
27
+ dotenv is initialized in your Rails app during the `before_configuration` callback, which is fired when the `Application` constant is defined in `config/application.rb` with `class Application < Rails::Application`. If you need it to be initialized sooner, you can manually call `Dotenv::Railtie.load`.
28
+
29
+ ```ruby
30
+ # config/application.rb
31
+ Bundler.require(*Rails.groups)
32
+
33
+ Dotenv::Railtie.load
34
+
35
+ HOSTNAME = ENV['HOSTNAME']
36
+ ```
37
+
38
+ 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`.
39
+
40
+ ```ruby
41
+ gem 'dotenv-rails', :require => 'dotenv/rails-now'
42
+ gem 'gem-that-requires-env-variables'
43
+ ```
44
+
45
+ ### Sinatra or Plain ol' Ruby
46
+
47
+ Install the gem:
48
+
49
+ ```shell
50
+ $ gem install dotenv
51
+ ```
52
+
53
+ As early as possible in your application bootstrap process, load `.env`:
54
+
55
+ ```ruby
56
+ require 'dotenv'
57
+ Dotenv.load
58
+ ```
59
+
60
+ Alternatively, you can use the `dotenv` executable to launch your application:
61
+
62
+ ```shell
63
+ $ dotenv ./script.py
64
+ ```
65
+
66
+ To ensure `.env` is loaded in rake, load the tasks:
67
+
68
+ ```ruby
69
+ require 'dotenv/tasks'
70
+
71
+ task :mytask => :dotenv do
72
+ # things that require .env
73
+ end
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ Add your application configuration to your `.env` file in the root of your project:
79
+
80
+ ```shell
81
+ S3_BUCKET=YOURS3BUCKET
82
+ SECRET_KEY=YOURSECRETKEYGOESHERE
83
+ ```
84
+
85
+ If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
86
+
87
+ ```shell
88
+ PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n"
89
+ ```
90
+
91
+ You may also add `export` in front of each line so you can `source` the file in bash:
92
+
93
+ ```shell
94
+ export S3_BUCKET=YOURS3BUCKET
95
+ export SECRET_KEY=YOURSECRETKEYGOESHERE
96
+ ```
97
+
98
+ Whenever your application loads, these variables will be available in `ENV`:
99
+
100
+ ```ruby
101
+ config.fog_directory = ENV['S3_BUCKET']
102
+ ```
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
+
112
+ ## Should I commit my .env file?
113
+
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.
115
+
116
+ 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.
117
+
118
+ ## Contributing
119
+
120
+ 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).
121
+
122
+ 1. Fork it
123
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
124
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
125
+ 4. Push to the branch (`git push origin my-new-feature`)
126
+ 5. Create new Pull Request
data/lib/dotenv/rails.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require 'dotenv'
2
+
3
+ Dotenv.instrumenter = ActiveSupport::Notifications
4
+
5
+ # Watch all loaded env files with Spring
2
6
  begin
3
7
  require 'spring/watcher'
8
+ ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ Spring.watch event.payload[:env].filename if Rails.application
11
+ end
4
12
  rescue LoadError
5
13
  # Spring is not available
6
14
  end
@@ -14,8 +22,18 @@ module Dotenv
14
22
  # This will get called during the `before_configuration` callback, but you
15
23
  # can manually call `Dotenv::Railtie.load` if you needed it sooner.
16
24
  def load
17
- Dotenv.load Rails.root.join('.env')
18
- Spring.watch Rails.root.join('.env') if defined?(Spring)
25
+ Dotenv.load(
26
+ root.join(".env.local"),
27
+ root.join(".env.#{Rails.env}"),
28
+ root.join('.env')
29
+ )
30
+ end
31
+
32
+ # Internal: `Rails.root` is nil in Rails 4.1 before the application is
33
+ # initialized, so this falls back to the `RAILS_ROOT` environment variable,
34
+ # or the current workding directory.
35
+ def root
36
+ Rails.root || Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd)
19
37
  end
20
38
 
21
39
  # Rails uses `#method_missing` to delegate all class methods to the
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: 1.0.2
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: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-01-22 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: 1.0.2
19
+ version: 2.0.0.beta
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: 1.0.2
26
+ version: 2.0.0.beta
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spring
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '4.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '4.0'
55
55
  description: Autoload dotenv in Rails.
56
56
  email:
57
57
  - brandon@opensoul.org
@@ -59,11 +59,11 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - dotenv-rails.gemspec
62
+ - LICENSE
63
+ - README.md
63
64
  - lib/dotenv-rails.rb
64
65
  - lib/dotenv/rails-now.rb
65
66
  - lib/dotenv/rails.rb
66
- - spec/dotenv/rails_spec.rb
67
67
  homepage: https://github.com/bkeepers/dotenv
68
68
  licenses:
69
69
  - MIT
@@ -79,14 +79,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - ">"
83
83
  - !ruby/object:Gem::Version
84
- version: '0'
84
+ version: 1.3.1
85
85
  requirements: []
86
86
  rubyforge_project:
87
87
  rubygems_version: 2.2.2
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Autoload dotenv in Rails.
91
- test_files:
92
- - spec/dotenv/rails_spec.rb
91
+ test_files: []
data/dotenv-rails.gemspec DELETED
@@ -1,22 +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{Autoload dotenv in Rails.}
9
- gem.summary = %q{Autoload dotenv in Rails.}
10
- gem.homepage = "https://github.com/bkeepers/dotenv"
11
- gem.license = 'MIT'
12
-
13
- gem.files = `git ls-files | grep rails`.split($\)
14
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
- gem.name = "dotenv-rails"
16
- gem.require_paths = ["lib"]
17
-
18
- gem.add_dependency 'dotenv', Dotenv::VERSION
19
-
20
- gem.add_development_dependency 'spring'
21
- gem.add_development_dependency 'railties'
22
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
- require 'rails'
3
- require 'dotenv/rails'
4
-
5
- describe Dotenv::Railtie do
6
- # Fake watcher for Spring
7
- class SpecWatcher < Struct.new(:items)
8
- def initialize
9
- @items = Set.new
10
- end
11
-
12
- def add(*items)
13
- @items.merge items
14
- end
15
- end
16
-
17
- before do
18
- allow(Rails).to receive(:root).and_return Pathname.new(File.expand_path('../../../', __FILE__))
19
- allow(Spring).to receive(:application_root_path).and_return(Rails.root)
20
- Spring.watcher = SpecWatcher.new
21
- end
22
-
23
- context 'before_configuration' do
24
- it 'calls #load' do
25
- expect(Dotenv::Railtie.instance).to receive(:load)
26
- ActiveSupport.run_load_hooks(:before_configuration)
27
- end
28
- end
29
-
30
- context 'load' do
31
- before { Dotenv::Railtie.load }
32
-
33
- it 'watches .env with Spring' do
34
- Spring.watcher.include? Rails.root.join('.env')
35
- end
36
-
37
- it 'loads .env' do
38
- expect(ENV).to have_key('DOTENV')
39
- end
40
- end
41
- end