unenviable 0.3.1 → 0.4.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: adbf42f9de156c23366902a3e3ba53acb74a608a
4
- data.tar.gz: d0a37d8500eba9e833ffa782653919c8476e2d66
3
+ metadata.gz: e53f26c91fdbb6c22519eeec6cf6e4b7cc71b2e8
4
+ data.tar.gz: d28fa7503819690f49ffda953190c36bc4d16f1e
5
5
  SHA512:
6
- metadata.gz: fa2e667820351e0d082a11a4f82145b48445db8b12c013b8b581706507bb4782e753d1b451fb96a2546a6901a5bd0d97161b7d85982f51b1012b46ced2854f07
7
- data.tar.gz: 7dca9612f7558a1ba4048ff2920f6fba34016bdb9645f046fcc9eeecbc24c5c497e9d18a82a05743524a16b34344aad8b2f56c5eaab45c2ec67949ac13094f35
6
+ metadata.gz: 9f6f5939b90757c89ab272c5d2730cc414d5fad680050ade6f0b30e7e78dcf9aa5b6441685e40f7666323326c001a4375408d448b17d85d05df02f4cbdfb5509
7
+ data.tar.gz: b05f9495175209b01ccc6c6a0803129bc72e953a91c57c6e852087ce073f3c8d424e6462a2c3598662f98d3e4fb308fe78ca21ce3975ce6f069e740e36f53d59
@@ -4,9 +4,11 @@ module Unenviable
4
4
  class ENVWrapper
5
5
  def initialize
6
6
  @saved_env = ENV
7
+ @closed = false
7
8
  end
8
9
 
9
10
  def [](key)
11
+ failed "Requested ENV[#{key}] after initialization finished!" if @closed
10
12
  value = @saved_env[key]
11
13
  fail "Requested ENV[#{key}] which has not been described!" unless Unenviable.described?(key)
12
14
  return value unless value.nil?
@@ -16,5 +18,9 @@ module Unenviable
16
18
  def []=(key, value)
17
19
  @saved_env[key] = value
18
20
  end
21
+
22
+ def close_wrapper
23
+ @closed = true
24
+ end
19
25
  end
20
26
  end
data/lib/unenviable.rb CHANGED
@@ -3,6 +3,7 @@ require 'dotenv'
3
3
  require 'yaml'
4
4
 
5
5
  require 'unenviable/env_wrapper'
6
+ require 'unenviable/railtie' if defined?(Rails)
6
7
 
7
8
  # Handles loading a YAML file that will describe what ENV variables
8
9
  # are necessary for a twelve-factor app in a specific environment.
@@ -42,18 +43,19 @@ module Unenviable
42
43
  end
43
44
 
44
45
  def self.generate
45
- load_env_descriptions unless @env_list
46
- File.new('.env', 'wb') do |f|
47
- generate_dotenv_lines.each { |l| f.write(l) }
46
+ File.open('.env', 'wb') do |f|
47
+ generate_dotenv_lines.each { |l| f.write(l + "\n") }
48
48
  end
49
49
  end
50
50
 
51
51
  def self.generate_dotenv_lines
52
+ load_env_descriptions unless @env_list
52
53
  lines = []
53
54
  @env_list.each do |var, details|
54
55
  lines << "# #{details[:description]}"
55
56
  lines << "#{var}=#{details[:initial_value]}" if details[:required]
56
57
  lines << "##{var}=#{details[:initial_value]}" unless details[:required]
58
+ lines << ''
57
59
  end
58
60
 
59
61
  lines
@@ -65,7 +67,12 @@ module Unenviable
65
67
  # this needn't be called directly, it's called lazily by the functions.
66
68
  def self.load_env_descriptions
67
69
  if File.file?(env_descriptions_file_location)
68
- @env_list = YAML.load(File.open(env_descriptions_file_location))
70
+ @base_env_list = YAML.load(File.open(env_descriptions_file_location))
71
+ @env_list = {}
72
+ @base_env_list.each do |var, details|
73
+ @env_list[var] = {}
74
+ details.each { |k, v| @env_list[var][k.to_sym] = v }
75
+ end
69
76
  else
70
77
  @env_list = {}
71
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unenviable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - K M Lawrence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.11.1
19
+ version: '0.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.11.1
26
+ version: '0.11'
27
27
  description: Makes ENV vars easier to keep track of in distributed development
28
28
  email: keith@kludge.co.uk
29
29
  executables: