dotenv 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +12 -0
- data/dotenv.gemspec +19 -0
- data/lib/dotenv.rb +9 -0
- data/lib/dotenv/environment.rb +22 -0
- data/lib/dotenv/railtie.rb +11 -0
- data/lib/dotenv/tasks.rb +7 -0
- data/spec/dotenv_spec.rb +32 -0
- data/spec/fixtures/plain.env +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +107 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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,54 @@
|
|
1
|
+
# dotenv
|
2
|
+
|
3
|
+
Loads environment settings for your application from `.env`.
|
4
|
+
|
5
|
+
The emerging practice of storing application configuration in environment variables is a great idea, but it's not always practical to set all of those environment variables in your development or continuous integration environments. [Foreman](https://github.com/ddollar/foreman) provides this handy feature of loading settings from `.env`, which works great for anything that you want to put in your `Procfile`. But it makes things difficult when you want to run a console or rake task. `dotenv` solves that problem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### Rails
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'dotenv', :groups => [:development, :test]
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
### Sinatra or Plain ol' Ruby
|
20
|
+
|
21
|
+
Install the gem:
|
22
|
+
|
23
|
+
$ gem install dotenv
|
24
|
+
|
25
|
+
As early as possible in your application bootstrap process, load `.env`:
|
26
|
+
|
27
|
+
Dotenv.load
|
28
|
+
|
29
|
+
To ensure `.env` is loaded in rake, load the tasks:
|
30
|
+
|
31
|
+
require 'dotenv/tasks'
|
32
|
+
|
33
|
+
task :mytask => :dotenv do
|
34
|
+
# things that require .env
|
35
|
+
end
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Add your application configuration to `.env`.
|
40
|
+
|
41
|
+
S3_BUCKET=dotenv
|
42
|
+
SECRET_KEY=sssshhh!
|
43
|
+
|
44
|
+
Whenever your application loads, these variables will be available in `ENV`:
|
45
|
+
|
46
|
+
config.fog_directory = ENV['S3_BUCKET']
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dotenv.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Brandon Keepers"]
|
5
|
+
gem.email = ["brandon@opensoul.org"]
|
6
|
+
gem.description = %q{Loads environment variables from `.env`.}
|
7
|
+
gem.summary = %q{Loads environment variables from `.env`.}
|
8
|
+
gem.homepage = "https://github.com/bkeepers/dotenv"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "dotenv"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = '0.1.0'
|
16
|
+
|
17
|
+
gem.add_development_dependency 'rake'
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
end
|
data/lib/dotenv.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dotenv
|
2
|
+
class Environment < Hash
|
3
|
+
def initialize(filename)
|
4
|
+
@filename = filename
|
5
|
+
load
|
6
|
+
end
|
7
|
+
|
8
|
+
def load
|
9
|
+
read.each do |line|
|
10
|
+
self[$1] = $2 if line =~ /\A([\w_]+)=(.*)\z/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def read
|
15
|
+
File.read(@filename).split("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def apply
|
19
|
+
each { |k,v| ENV[k] = v }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/dotenv/tasks.rb
ADDED
data/spec/dotenv_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dotenv::Environment do
|
4
|
+
let(:env_path) { fixture_path('plain.env') }
|
5
|
+
let(:dotenv) { Dotenv::Environment.new(env_path) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@env_keys = ENV.keys
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
ENV.delete_if { |k,v| !@env_keys.include?(k) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'initialize' do
|
16
|
+
it 'reads environment config' do
|
17
|
+
expect(dotenv['OPTION_A']).to eq('1')
|
18
|
+
expect(dotenv['OPTION_B']).to eq('2')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'apply' do
|
23
|
+
it 'sets variables in ENV' do
|
24
|
+
dotenv.apply
|
25
|
+
expect(ENV['OPTION_A']).to eq('1')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def fixture_path(name)
|
30
|
+
File.join(File.expand_path('../fixtures', __FILE__), name)
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dotenv'
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dotenv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brandon Keepers
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Loads environment variables from `.env`.
|
49
|
+
email:
|
50
|
+
- brandon@opensoul.org
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- dotenv.gemspec
|
64
|
+
- lib/dotenv.rb
|
65
|
+
- lib/dotenv/environment.rb
|
66
|
+
- lib/dotenv/railtie.rb
|
67
|
+
- lib/dotenv/tasks.rb
|
68
|
+
- spec/dotenv_spec.rb
|
69
|
+
- spec/fixtures/plain.env
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: https://github.com/bkeepers/dotenv
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.15
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Loads environment variables from `.env`.
|
104
|
+
test_files:
|
105
|
+
- spec/dotenv_spec.rb
|
106
|
+
- spec/fixtures/plain.env
|
107
|
+
- spec/spec_helper.rb
|