denv 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -4
- data/denv.gemspec +1 -1
- data/lib/denv.rb +18 -2
- data/lib/denv/rails.rb +2 -10
- data/lib/denv/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8dc02ec38953c284f7e3683d224f5eedbc73f63
|
4
|
+
data.tar.gz: b71b09fa0d21d8a24496a52e418b68bfbcef25ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b58bd7a2c6e6c0fd59780d072210c8bdf0403f07e3b3b1ad770a2ebabad35423862f13969e96431193e528a929d9a64c0d124362d4d072066d584013e2d44245
|
7
|
+
data.tar.gz: 4073d21e171d9b0d10801b29b940a897526ab7743f8a4b2380f360af9396c40873b6e3ea8f072e5545d00464310b17a30bea38fcc3e954e410f211361f83b47d
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# denv
|
2
|
+
[](https://travis-ci.org/taiki45/denv) [](https://badge.fury.io/rb/denv)
|
3
|
+
|
2
4
|
denv = dotenv + Docker envfile format
|
3
5
|
|
4
|
-
|
6
|
+
Loads environment variables to `ENV` from `.env` file.
|
7
|
+
|
8
|
+
- No special treatments about shell meta characters (e.g. `$`).
|
9
|
+
- Behaves as over-write.
|
5
10
|
|
6
11
|
## Usage
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -19,10 +24,21 @@ And then execute:
|
|
19
24
|
$ bundle
|
20
25
|
```
|
21
26
|
|
22
|
-
|
27
|
+
Write your envfile at `.env`:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
AWESOME_SERVICE_CREDENTIAL=xxxxxx
|
31
|
+
ANOTHER_CREDENTIAL=xxxxxx
|
32
|
+
```
|
33
|
+
|
34
|
+
Then call `Denv.load` in your application initialization. Now you can refer env vars via `ENV`.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
puts ENV['AWESOME_SERVICE_CREDENTIAL'] #=> "xxxxxx"
|
38
|
+
```
|
23
39
|
|
24
40
|
### Rails integration
|
25
|
-
|
41
|
+
denv automatically sets initializer for your Rails application, so you only have to write gem dependency to your Gemfile.
|
26
42
|
|
27
43
|
## Development
|
28
44
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -30,7 +46,7 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
30
46
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
47
|
|
32
48
|
## Contributing
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/taiki45/denv.
|
34
50
|
|
35
51
|
|
36
52
|
## License
|
data/denv.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Taiki Ono']
|
9
9
|
spec.email = ['taiks.4559@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = %q{
|
11
|
+
spec.summary = %q{Loads environment variables to `ENV` from `.env` file. No special treatments about shell meta characters.}
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = 'https://github.com/taiki45/denv'
|
14
14
|
spec.license = 'MIT'
|
data/lib/denv.rb
CHANGED
@@ -27,12 +27,28 @@ module Denv
|
|
27
27
|
|
28
28
|
attr_accessor :callback
|
29
29
|
|
30
|
+
# Read from .env file and load vars into `ENV`.
|
31
|
+
# Default is over-write.
|
32
|
+
# @param [String] filename
|
33
|
+
# @return [Hash] env
|
30
34
|
def load(filename = DEFAULT_ENV_FILENAME)
|
31
35
|
filename = File.expand_path(filename.to_s)
|
32
36
|
run_callback(filename) do
|
33
|
-
|
34
|
-
env.each {|k, v| ENV[k] ||= v }
|
37
|
+
build_env(filename).each {|k, v| ENV[k] = v }
|
35
38
|
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Read from .env file and build env Hash.
|
42
|
+
# @param [String] filename
|
43
|
+
# @return [Hash] loaded environment variables
|
44
|
+
def build_env(filename)
|
45
|
+
open_file(filename) {|f| Parser.new(f, filename).parse }
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def open_file(filename)
|
51
|
+
File.open(filename) {|f| yield f }
|
36
52
|
rescue Errno::ENOENT
|
37
53
|
raise NoSuchFileError.new(filename)
|
38
54
|
end
|
data/lib/denv/rails.rb
CHANGED
@@ -12,9 +12,9 @@ module Denv
|
|
12
12
|
class Railtie < ::Rails::Railtie
|
13
13
|
DEFAULT_ENV_FILES = %w[.env.local .env.#{Rails.env} .env]
|
14
14
|
|
15
|
-
config.before_configuration {
|
15
|
+
config.before_configuration { load_env }
|
16
16
|
|
17
|
-
def
|
17
|
+
def load_env
|
18
18
|
DEFAULT_ENV_FILES.map {|name| root.join(name) }.select(&:exist?).each do |path|
|
19
19
|
Denv.load(path)
|
20
20
|
end
|
@@ -23,13 +23,5 @@ module Denv
|
|
23
23
|
def root
|
24
24
|
Rails.root || Pathname.new(ENV['RAILS_ROOT'] || Dir.pwd)
|
25
25
|
end
|
26
|
-
|
27
|
-
# Brought from dotenv.
|
28
|
-
#
|
29
|
-
# Rails uses `#method_missing` to delegate all class methods to the
|
30
|
-
# instance, which means `Kernel#load` gets called here. We don't want that.
|
31
|
-
def self.load
|
32
|
-
instance.load
|
33
|
-
end
|
34
26
|
end
|
35
27
|
end
|
data/lib/denv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: denv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taiki Ono
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,8 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3'
|
69
|
-
description:
|
69
|
+
description: Loads environment variables to `ENV` from `.env` file. No special treatments
|
70
|
+
about shell meta characters.
|
70
71
|
email:
|
71
72
|
- taiks.4559@gmail.com
|
72
73
|
executables: []
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- ".gitignore"
|
77
78
|
- ".rspec"
|
78
79
|
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
79
81
|
- Gemfile
|
80
82
|
- LICENSE.txt
|
81
83
|
- README.md
|
@@ -110,5 +112,6 @@ rubyforge_project:
|
|
110
112
|
rubygems_version: 2.5.1
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
|
-
summary:
|
115
|
+
summary: Loads environment variables to `ENV` from `.env` file. No special treatments
|
116
|
+
about shell meta characters.
|
114
117
|
test_files: []
|