denv 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +23 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/denv.gemspec +25 -0
- data/lib/denv.rb +80 -0
- data/lib/denv/rails.rb +35 -0
- data/lib/denv/version.rb +3 -0
- data/rails_integration_test.rb +25 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0944471b087e3b02a91ff4b3096812e0643b641
|
4
|
+
data.tar.gz: 86af88174173f473634b43cbabfcbb9dec6deca4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83f3759e5d7ded69567d3fd1bfd7d7a742a393fced3c9124c1ac066ec91fda7abab6c7add2fe9026c79ec378be957f420f3979aaa3815b6a5cb070fa7aa68457
|
7
|
+
data.tar.gz: 863e6dc9d1c586dc8f00aff14cc28882bd7490ce02e510282c47b1411a61cce14d4b43b008df0186cb9bb57e1362c9108fa98933a502d947caa11bd923a67756
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Taiki Ono
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# denv
|
2
|
+
denv = dotenv + Docker envfile format
|
3
|
+
|
4
|
+
No special treatments about shell meta characters (e.g. `$`).
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
source 'https://rubygems.org'
|
11
|
+
|
12
|
+
# Place this line at very top of your Gemfile
|
13
|
+
gem 'denv'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Then call `Denv.load` in your application initialization.
|
23
|
+
|
24
|
+
### Rails integration
|
25
|
+
Denv automatically set initializer for your Rails application, so you only have to write gem dependency to your Gemfile.
|
26
|
+
|
27
|
+
## Development
|
28
|
+
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.
|
29
|
+
|
30
|
+
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
|
+
|
32
|
+
## Contributing
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/denv.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :test
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Run all tests'
|
11
|
+
task :test do
|
12
|
+
Rake::Task[:spec].invoke
|
13
|
+
Rake::Task[:integration_test].invoke
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Run Rails integration test'
|
17
|
+
task :integration_test do
|
18
|
+
exit(1) unless execute_without_bundler { ruby('rails_integration_test.rb') }
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute_without_bundler
|
22
|
+
defined?(Bundler) ? Bundler.with_clean_env { yield } : yield
|
23
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "denv"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/denv.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'denv/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'denv'
|
7
|
+
spec.version = Denv::VERSION
|
8
|
+
spec.authors = ['Taiki Ono']
|
9
|
+
spec.email = ['taiks.4559@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q{dotenv + Docker envfile. No special treatments about shell meta characters.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/taiki45/denv'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rails'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
25
|
+
end
|
data/lib/denv.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "denv/version"
|
2
|
+
|
3
|
+
module Denv
|
4
|
+
class Error < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class NoSuchFileError < Error
|
8
|
+
def initialize(filename)
|
9
|
+
super("Can not find envfile: #{filename}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class InvalidFormatError < Error
|
14
|
+
def initialize(line, filename, lineno)
|
15
|
+
super("key and value must be separated by `=`: #{filename}:#{lineno}: #{line}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidKeyNameError < Error
|
20
|
+
def initialize(line, filename, lineno)
|
21
|
+
super("key can not contain whitespaces: #{filename}:#{lineno}: #{line}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
DEFAULT_ENV_FILENAME = '.env'.freeze
|
27
|
+
|
28
|
+
attr_accessor :callback
|
29
|
+
|
30
|
+
def load(filename = DEFAULT_ENV_FILENAME)
|
31
|
+
filename = File.expand_path(filename.to_s)
|
32
|
+
run_callback(filename) do
|
33
|
+
env = File.open(filename) {|f| Parser.new(f, filename).parse }
|
34
|
+
env.each {|k, v| ENV[k] ||= v }
|
35
|
+
end
|
36
|
+
rescue Errno::ENOENT
|
37
|
+
raise NoSuchFileError.new(filename)
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_callback(filename)
|
41
|
+
callback.call(filename) if callback
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Parser
|
47
|
+
COMMENT_CHAR = '#'
|
48
|
+
DELIMITER = '='
|
49
|
+
WHITE_SPACES = /\s/
|
50
|
+
|
51
|
+
def initialize(io, filename)
|
52
|
+
@io = io
|
53
|
+
@filename = filename
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse
|
57
|
+
env = {}
|
58
|
+
|
59
|
+
@io.each_line.with_index do |line, i|
|
60
|
+
line = line.chomp.lstrip
|
61
|
+
if !line.empty? && !line.start_with?(COMMENT_CHAR)
|
62
|
+
key, value = line.split(DELIMITER, 2)
|
63
|
+
if key && value
|
64
|
+
if key.match(WHITE_SPACES)
|
65
|
+
raise InvalidKeyNameError.new(line, @filename, i + 1)
|
66
|
+
else
|
67
|
+
env[key] = value
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise InvalidFormatError.new(line, @filename, i + 1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
env
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
require 'denv/rails' if defined?(Rails)
|
data/lib/denv/rails.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Watch all loaded env files with Spring
|
2
|
+
begin
|
3
|
+
require 'spring/watcher'
|
4
|
+
Denv.callback = -> (filename) do
|
5
|
+
Spring.watch(filename) if Rails.application
|
6
|
+
end
|
7
|
+
rescue LoadError
|
8
|
+
# Spring is not available
|
9
|
+
end
|
10
|
+
|
11
|
+
module Denv
|
12
|
+
class Railtie < ::Rails::Railtie
|
13
|
+
DEFAULT_ENV_FILES = %w[.env.local .env.#{Rails.env} .env]
|
14
|
+
|
15
|
+
config.before_configuration { load }
|
16
|
+
|
17
|
+
def load
|
18
|
+
DEFAULT_ENV_FILES.map {|name| root.join(name) }.select(&:exist?).each do |path|
|
19
|
+
Denv.load(path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def root
|
24
|
+
Rails.root || Pathname.new(ENV['RAILS_ROOT'] || Dir.pwd)
|
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
|
+
end
|
35
|
+
end
|
data/lib/denv/version.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
name = 'denv_test'
|
4
|
+
path = File.expand_path(__dir__)
|
5
|
+
|
6
|
+
system('bundle install -j8')
|
7
|
+
FileUtils.rm_rf('tmp')
|
8
|
+
FileUtils.mkdir_p('tmp')
|
9
|
+
Dir.chdir('tmp') do
|
10
|
+
system("bundle exec rails new #{name} --skip-bundle")
|
11
|
+
Dir.chdir(name) do
|
12
|
+
lines = File.read('Gemfile').split("\n")
|
13
|
+
new = lines.first(1) + [%!gem "denv", path: "#{path}"!] + lines.drop(1)
|
14
|
+
File.open('Gemfile', 'w') {|f| f.puts(new.join("\n")) }
|
15
|
+
system('bundle install -j8')
|
16
|
+
File.open('.env', 'w') {|f| f.puts("XXX=123\nYYY=1\n") }
|
17
|
+
result = system(%!bundle exec rails runner 'ENV["XXX"] == "123" ? exit : exit(1)'!)
|
18
|
+
if result
|
19
|
+
puts "[#{name}] Succeeded"
|
20
|
+
else
|
21
|
+
$stderr.puts "[#{name}] Failed"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: denv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taiki Ono
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description: dotenv + Docker envfile. No special treatments about shell meta characters.
|
70
|
+
email:
|
71
|
+
- taiks.4559@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- denv.gemspec
|
86
|
+
- lib/denv.rb
|
87
|
+
- lib/denv/rails.rb
|
88
|
+
- lib/denv/version.rb
|
89
|
+
- rails_integration_test.rb
|
90
|
+
homepage: https://github.com/taiki45/denv
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: dotenv + Docker envfile. No special treatments about shell meta characters.
|
114
|
+
test_files: []
|