denv 0.1.0 → 0.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: f0944471b087e3b02a91ff4b3096812e0643b641
4
- data.tar.gz: 86af88174173f473634b43cbabfcbb9dec6deca4
3
+ metadata.gz: e8dc02ec38953c284f7e3683d224f5eedbc73f63
4
+ data.tar.gz: b71b09fa0d21d8a24496a52e418b68bfbcef25ad
5
5
  SHA512:
6
- metadata.gz: 83f3759e5d7ded69567d3fd1bfd7d7a742a393fced3c9124c1ac066ec91fda7abab6c7add2fe9026c79ec378be957f420f3979aaa3815b6a5cb070fa7aa68457
7
- data.tar.gz: 863e6dc9d1c586dc8f00aff14cc28882bd7490ce02e510282c47b1411a61cce14d4b43b008df0186cb9bb57e1362c9108fa98933a502d947caa11bd923a67756
6
+ metadata.gz: b58bd7a2c6e6c0fd59780d072210c8bdf0403f07e3b3b1ad770a2ebabad35423862f13969e96431193e528a929d9a64c0d124362d4d072066d584013e2d44245
7
+ data.tar.gz: 4073d21e171d9b0d10801b29b940a897526ab7743f8a4b2380f360af9396c40873b6e3ea8f072e5545d00464310b17a30bea38fcc3e954e410f211361f83b47d
@@ -0,0 +1,4 @@
1
+ # CHANGELOG.md for denv
2
+ ## 0.2.0
3
+ - Behaves as over-write.
4
+ - Add `Denv.build_env(filename)` to load and get env hash.
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  # denv
2
+ [![Build Status](https://travis-ci.org/taiki45/denv.svg?branch=master)](https://travis-ci.org/taiki45/denv) [![Gem Version](https://badge.fury.io/rb/denv.svg)](https://badge.fury.io/rb/denv)
3
+
2
4
  denv = dotenv + Docker envfile format
3
5
 
4
- No special treatments about shell meta characters (e.g. `$`).
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
- Then call `Denv.load` in your application initialization.
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
- Denv automatically set initializer for your Rails application, so you only have to write gem dependency to your Gemfile.
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/[USERNAME]/denv.
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/taiki45/denv.
34
50
 
35
51
 
36
52
  ## License
@@ -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{dotenv + Docker envfile. No special treatments about shell meta characters.}
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'
@@ -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
- env = File.open(filename) {|f| Parser.new(f, filename).parse }
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
@@ -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 { load }
15
+ config.before_configuration { load_env }
16
16
 
17
- def load
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
@@ -1,3 +1,3 @@
1
1
  module Denv
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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-07 00:00:00.000000000 Z
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: dotenv + Docker envfile. No special treatments about shell meta characters.
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: dotenv + Docker envfile. No special treatments about shell meta characters.
115
+ summary: Loads environment variables to `ENV` from `.env` file. No special treatments
116
+ about shell meta characters.
114
117
  test_files: []