unenviable 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/unenviable.rb +44 -2
- metadata +19 -3
data/lib/unenviable.rb
CHANGED
@@ -1,8 +1,50 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'dotenv'
|
2
3
|
require 'yaml'
|
3
4
|
|
5
|
+
# Handles loading a YAML file that will describe what ENV variables
|
6
|
+
# are necessary for a twelve-factor app in a specific environment.
|
4
7
|
module Unenviable
|
5
|
-
def check
|
6
|
-
|
8
|
+
def self.check
|
9
|
+
load_env_descriptions unless @env_list
|
10
|
+
Dotenv.load
|
11
|
+
discrepancies = { required: [], optional: [], forbidden: [] }
|
12
|
+
|
13
|
+
@env_list.each do |var, details|
|
14
|
+
discrepancies[:required] << var if details[:required] && !ENV[var]
|
15
|
+
discrepancies[:optional] << var if !details[:required] && !details[:forbidden] && !ENV[var]
|
16
|
+
discrepancies[:forbidden] << var if details[:forbidden] && ENV[var]
|
17
|
+
end
|
18
|
+
|
19
|
+
discrepancies
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_minimum_dotenv
|
23
|
+
load_env_descriptions unless @env_list
|
24
|
+
File.new('.env', 'wb') do |f|
|
25
|
+
@env_list.each do |var, details|
|
26
|
+
f.write("export #{var}=#{details['initial_value']}") if details[:required]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.env_descriptions_file_location
|
32
|
+
'config/unenviable.yml'
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.env_descriptions=(env_list)
|
36
|
+
@env_list = env_list
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Load the file that descriptions the required environment variables
|
42
|
+
# this needn't be called directly, it's called lazily by the functions.
|
43
|
+
def self.load_env_descriptions
|
44
|
+
if File.file?(env_descriptions_file_location)
|
45
|
+
@env_list = YAML.load(File.open(env_descriptions_file_location))
|
46
|
+
else
|
47
|
+
@env_list = {}
|
48
|
+
end
|
7
49
|
end
|
8
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unenviable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
13
|
-
dependencies:
|
12
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dotenv
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.11.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.11.1
|
14
30
|
description: Makes ENV vars easier to keep track of in distributed development
|
15
31
|
email: keith@kludge.co.uk
|
16
32
|
executables:
|