dotenvious 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 729dd3bb01a80922fc0db320fcaa80c4c58f269f
4
- data.tar.gz: 093d53d8abeb5a7de6fddebe2985cb4a28ddfc5c
3
+ metadata.gz: 05b9cfc0c1060c40bfbbf274f483ae4d351991f6
4
+ data.tar.gz: 1c9bc373c7b9f4f49300bbb1046f4abc71a635b5
5
5
  SHA512:
6
- metadata.gz: a688ece6d08099e7fba7e527e9400fd4e40cdea906384ae5e1e4c6761bd8396453e487993fe611428d97653893f1e6e88c6de2fad4e07e748a8aa67719e95139
7
- data.tar.gz: a5a3969e275bc327de6ad6b1277ba5d0eec0814f9947fafaeb4d71df85113232b02aa4e5d4817bfde9193d394269ce497a992dea3fa722401175a82307758d27
6
+ metadata.gz: e7b431f326f238f3212e7a2602f829c61c141c43412d9b13ed618af526719bb572f5fde8f54425cbacad9eb7e2d4b73a204a720d5e56a8db95ec6f2038f03d03
7
+ data.tar.gz: 61213d32ed4d838ff06b5c261761a24eb4773a557a0d357a1b919c5ed3589b935befcac929735bbebd81d64cc8c07d25c84ddab4e8bfb9cca3a892963d33ff3c
data/dotenvious.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dotenvious'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.6'
4
4
  s.date = '2017-01-08'
5
5
  s.summary = "Dotenvious"
6
6
  s.description = "A Gem to manage environment variables"
@@ -1,4 +1,5 @@
1
1
  require_relative 'dotenv_file'
2
+ require_relative 'yaml_file'
2
3
 
3
4
  module Dotenvious
4
5
  module Loaders
@@ -9,7 +10,8 @@ module Dotenvious
9
10
 
10
11
  def load_environments
11
12
  ENV.merge!(DotenvFile.load_from('.env'))
12
- ENV_EXAMPLE.merge!(DotenvFile.load_from(example_file))
13
+ environment_loader = example_file.match(/\.ya?ml/) ? YamlFile : DotenvFile
14
+ ENV_EXAMPLE.merge!(environment_loader.load_from(example_file))
13
15
  end
14
16
 
15
17
  private
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ module Dotenvious
4
+ module Loaders
5
+ class YamlFile
6
+ def self.load_from(filename)
7
+ new(filename).load
8
+ end
9
+
10
+ def initialize(filename)
11
+ @filename = filename
12
+ end
13
+
14
+ def load
15
+ if file_missing?
16
+ puts "This repo does not have an #{filename} file"
17
+ return {}
18
+ end
19
+ Hash.new.tap do |environment|
20
+ environment_variables.each do |(k, v)|
21
+ environment[k] = v.to_s
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :filename
29
+
30
+ def file_missing?
31
+ !File.exists?(filename)
32
+ end
33
+
34
+ def file
35
+ YAML.load_file(filename)
36
+ end
37
+
38
+ def environment_variables
39
+ begin
40
+ file['machine']['environment']
41
+ rescue NoMethodError => e
42
+ puts "Error: #{filename} does not have a proper machine environment setup."
43
+ puts "The program will now exit."
44
+ exit
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -24,6 +24,22 @@ describe Dotenvious::Loaders::Environments do
24
24
 
25
25
  described_class.new({example_file: '.my.example.file'}).load_environments
26
26
  end
27
+
28
+ context 'which is a yml/yaml' do
29
+ it 'loads the yml correctly' do
30
+ expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.env').and_return({})
31
+ expect(Dotenvious::Loaders::YamlFile).to receive(:load_from).with('example.yml').and_return({})
32
+
33
+ described_class.new({example_file: 'example.yml'}).load_environments
34
+ end
35
+
36
+ it 'also loads yaml files' do
37
+ expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.env').and_return({})
38
+ expect(Dotenvious::Loaders::YamlFile).to receive(:load_from).with('example.yaml').and_return({})
39
+
40
+ described_class.new({example_file: 'example.yaml'}).load_environments
41
+ end
42
+ end
27
43
  end
28
44
  end
29
45
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dotenvious::Loaders::YamlFile do
4
+ describe '.load_from' do
5
+ context 'given a file which does not exist' do
6
+ before do
7
+ expect(File).to receive(:exists?).and_return false
8
+ end
9
+ it 'aborts the process' do
10
+ described_class.load_from('.env')
11
+ end
12
+ end
13
+
14
+ context 'given a file which exists' do
15
+ before do
16
+ expect(File).to receive(:exists?).and_return true
17
+ end
18
+
19
+ it 'reads the given Yaml format file and returns hash' do
20
+ expect(YAML).to receive(:load_file).and_return ({
21
+ "machine" => {
22
+ "environment" => {
23
+ "TEST" => 123,
24
+ "EXAMPLE" => 234
25
+ }
26
+ }
27
+ })
28
+
29
+ response = described_class.load_from('production.yaml')
30
+
31
+ expect(response['TEST']).to eq '123'
32
+ expect(response['EXAMPLE']).to eq '234'
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenvious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Faris
@@ -74,6 +74,7 @@ files:
74
74
  - lib/dotenvious/loaders/configuration.rb
75
75
  - lib/dotenvious/loaders/dotenv_file.rb
76
76
  - lib/dotenvious/loaders/environments.rb
77
+ - lib/dotenvious/loaders/yaml_file.rb
77
78
  - lib/dotenvious/mismatched_variable_finder.rb
78
79
  - lib/dotenvious/missing_variable_finder.rb
79
80
  - lib/dotenvious/prompter.rb
@@ -86,6 +87,7 @@ files:
86
87
  - spec/dotenvious/loaders/configuration_spec.rb
87
88
  - spec/dotenvious/loaders/dotenv_file_spec.rb
88
89
  - spec/dotenvious/loaders/environments_spec.rb
90
+ - spec/dotenvious/loaders/yaml_file_spec.rb
89
91
  - spec/dotenvious/mismatched_variable_finder_spec.rb
90
92
  - spec/dotenvious/missing_variable_finder_spec.rb
91
93
  - spec/dotenvious/prompter_spec.rb