dotenvious 0.0.4 → 0.0.5
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 +4 -4
- data/dotenvious.gemspec +2 -2
- data/lib/dotenvious/cli/env_file_consolidator.rb +6 -2
- data/lib/dotenvious/cli/env_file_sorter.rb +0 -4
- data/lib/dotenvious/cli/main.rb +32 -10
- data/lib/dotenvious/loaders/{environment.rb → dotenv_file.rb} +16 -12
- data/lib/dotenvious/loaders/environments.rb +12 -5
- data/spec/dotenvious/cli/env_file_consolidator_spec.rb +15 -4
- data/spec/dotenvious/cli/env_file_sorter_spec.rb +0 -2
- data/spec/dotenvious/cli/main_spec.rb +38 -5
- data/spec/dotenvious/loaders/dotenv_file_spec.rb +29 -0
- data/spec/dotenvious/loaders/environments_spec.rb +22 -5
- metadata +4 -7
- data/lib/dotenvious/loaders/env.rb +0 -15
- data/lib/dotenvious/loaders/example.rb +0 -17
- data/spec/dotenvious/loaders/env_spec.rb +0 -34
- data/spec/dotenvious/loaders/example_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 729dd3bb01a80922fc0db320fcaa80c4c58f269f
|
4
|
+
data.tar.gz: 093d53d8abeb5a7de6fddebe2985cb4a28ddfc5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a688ece6d08099e7fba7e527e9400fd4e40cdea906384ae5e1e4c6761bd8396453e487993fe611428d97653893f1e6e88c6de2fad4e07e748a8aa67719e95139
|
7
|
+
data.tar.gz: a5a3969e275bc327de6ad6b1277ba5d0eec0814f9947fafaeb4d71df85113232b02aa4e5d4817bfde9193d394269ce497a992dea3fa722401175a82307758d27
|
data/dotenvious.gemspec
CHANGED
@@ -6,9 +6,13 @@ require_relative '../loaders/configuration'
|
|
6
6
|
module Dotenvious
|
7
7
|
module CLI
|
8
8
|
class EnvFileConsolidator
|
9
|
+
def initialize(options = {})
|
10
|
+
@example_file = options[:example_file]
|
11
|
+
end
|
12
|
+
|
9
13
|
def run
|
10
14
|
Loaders::Configuration.new.load
|
11
|
-
Loaders::Environments.new.
|
15
|
+
Loaders::Environments.new({example_file: example_file}).load_environments
|
12
16
|
unless all_vars_present? && all_vars_match?
|
13
17
|
alert_user
|
14
18
|
decision = STDIN.gets.strip
|
@@ -18,7 +22,7 @@ module Dotenvious
|
|
18
22
|
|
19
23
|
private
|
20
24
|
|
21
|
-
attr_reader :filename
|
25
|
+
attr_reader :example_file, :filename
|
22
26
|
|
23
27
|
def alert_user
|
24
28
|
puts "You have missing ENV variables. Examime them? [y/n]"
|
data/lib/dotenvious/cli/main.rb
CHANGED
@@ -1,25 +1,47 @@
|
|
1
|
+
require 'optparse'
|
1
2
|
require_relative 'env_file_consolidator'
|
2
3
|
require_relative 'env_file_sorter'
|
3
4
|
|
4
5
|
module Dotenvious
|
5
6
|
module CLI
|
6
7
|
class Main
|
8
|
+
def initialize
|
9
|
+
@options = {}
|
10
|
+
end
|
11
|
+
|
7
12
|
def run
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
EnvFileSorter.new.run
|
12
|
-
else
|
13
|
-
ask_user_to_remove_flags
|
14
|
-
end
|
13
|
+
parse_options
|
14
|
+
EnvFileConsolidator.new({example_file: options[:file]}).run
|
15
|
+
EnvFileSorter.new.run if options[:sort]
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
18
19
|
|
19
|
-
|
20
|
+
attr_accessor :options
|
21
|
+
|
22
|
+
def parse_options
|
23
|
+
parser = OptionParser.new do |opts|
|
24
|
+
opts.banner = "How to use Dotenvious:"
|
25
|
+
|
26
|
+
opts.on('-f .example-environment-file', '--file .example-environment-file', 'Specify which example file to use') do |file|
|
27
|
+
options[:file] = file
|
28
|
+
end
|
20
29
|
|
21
|
-
|
22
|
-
|
30
|
+
opts.on('-s', '--sort', 'Sort .env file by key names alphabetically') do
|
31
|
+
options[:sort] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-h', '--help', 'View this message') do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
parser.parse!
|
42
|
+
rescue OptionParser::InvalidOption => e
|
43
|
+
puts "Warning #{e}"
|
44
|
+
end
|
23
45
|
end
|
24
46
|
end
|
25
47
|
end
|
@@ -1,31 +1,35 @@
|
|
1
1
|
module Dotenvious
|
2
2
|
module Loaders
|
3
|
-
class
|
3
|
+
class DotenvFile
|
4
|
+
def self.load_from(filename)
|
5
|
+
new(filename).load
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(filename)
|
9
|
+
@filename = filename
|
10
|
+
end
|
11
|
+
|
4
12
|
def load
|
5
13
|
#took from Dotenv source code whoops
|
6
14
|
if file_missing?
|
7
15
|
puts "This repo does not have an #{filename} file"
|
8
|
-
return
|
16
|
+
return {}
|
9
17
|
end
|
10
|
-
|
11
|
-
|
18
|
+
Hash.new.tap do |environment|
|
19
|
+
file.each do |line|
|
20
|
+
environment[$1] = $2 if line =~ /\A([\w_]+)=(.*)\z/
|
21
|
+
end
|
12
22
|
end
|
13
23
|
end
|
14
24
|
|
15
25
|
private
|
16
26
|
|
27
|
+
attr_reader :filename
|
28
|
+
|
17
29
|
def file_missing?
|
18
30
|
!File.exists?(filename)
|
19
31
|
end
|
20
32
|
|
21
|
-
def environment
|
22
|
-
raise "environment must be defined in child class"
|
23
|
-
end
|
24
|
-
|
25
|
-
def filename
|
26
|
-
raise "fileame must be defined in child class"
|
27
|
-
end
|
28
|
-
|
29
33
|
def file
|
30
34
|
File.read(filename).split("\n")
|
31
35
|
end
|
@@ -1,13 +1,20 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative 'env'
|
1
|
+
require_relative 'dotenv_file'
|
3
2
|
|
4
3
|
module Dotenvious
|
5
4
|
module Loaders
|
6
5
|
class Environments
|
7
|
-
def
|
8
|
-
|
9
|
-
Example.new.load
|
6
|
+
def initialize(options = {})
|
7
|
+
@example_file = options[:example_file] || DEFAULT_EXAMPLE_ENV_FILE
|
10
8
|
end
|
9
|
+
|
10
|
+
def load_environments
|
11
|
+
ENV.merge!(DotenvFile.load_from('.env'))
|
12
|
+
ENV_EXAMPLE.merge!(DotenvFile.load_from(example_file))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :example_file
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Dotenvious::CLI::EnvFileConsolidator do
|
4
4
|
describe '.new' do
|
5
|
-
|
6
|
-
|
5
|
+
it 'takes option hash' do
|
6
|
+
expect { described_class.new({example_file: '.envenvenv'}) }.to_not raise_error
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#run' do
|
11
|
-
context '
|
11
|
+
context 'without options' do
|
12
12
|
before do
|
13
13
|
allow(File).to receive(:read).and_return("")
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'loads the environment & example environment variables' do
|
17
|
-
expect_any_instance_of(Dotenvious::Loaders::Environments).to receive(:
|
17
|
+
expect_any_instance_of(Dotenvious::Loaders::Environments).to receive(:load_environments)
|
18
18
|
|
19
19
|
described_class.new.run
|
20
20
|
end
|
@@ -51,5 +51,16 @@ describe Dotenvious::CLI::EnvFileConsolidator do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
context 'given an option hash with :example_file' do
|
56
|
+
it 'loads environments with that example_file' do
|
57
|
+
environments_double = double
|
58
|
+
expect(Dotenvious::Loaders::Environments).to receive(:new)
|
59
|
+
.with({example_file: '.test.env.test'}).and_return(environments_double)
|
60
|
+
expect(environments_double).to receive(:load_environments)
|
61
|
+
|
62
|
+
described_class.new({example_file: '.test.env.test'}).run
|
63
|
+
end
|
64
|
+
end
|
54
65
|
end
|
55
66
|
end
|
@@ -3,8 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Dotenvious::CLI::EnvFileSorter do
|
4
4
|
describe '#run' do
|
5
5
|
it "sorts the key-value pairs back into .env" do
|
6
|
-
expect_any_instance_of(Dotenvious::Loaders::Env).to receive(:load).and_return true
|
7
|
-
|
8
6
|
stub_const('Dotenvious::ENV', {'TEST' => 'same', 'ABC' => '123'} )
|
9
7
|
|
10
8
|
fake_file = double
|
@@ -15,14 +15,47 @@ describe Dotenvious::CLI::Main do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when option flags are given' do
|
18
|
-
|
19
|
-
|
18
|
+
context 'and the flag is not implemented' do
|
19
|
+
before do
|
20
|
+
stub_const('ARGV', ['--test'])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'ignores the flag and runs main process' do
|
24
|
+
expect_any_instance_of(Dotenvious::CLI::EnvFileConsolidator).to receive(:run)
|
25
|
+
|
26
|
+
described_class.new.run
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
|
-
|
23
|
-
|
30
|
+
context 'and the flag is implemented' do
|
31
|
+
context '--sort' do
|
32
|
+
before do
|
33
|
+
stub_const('ARGV', ['--sort'])
|
34
|
+
end
|
24
35
|
|
25
|
-
|
36
|
+
it 'runs EnvFileSorter after main process' do
|
37
|
+
expect_any_instance_of(Dotenvious::CLI::EnvFileConsolidator).to receive(:run)
|
38
|
+
expect_any_instance_of(Dotenvious::CLI::EnvFileSorter).to receive(:run)
|
39
|
+
|
40
|
+
described_class.new.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '--file' do
|
45
|
+
before do
|
46
|
+
stub_const('ARGV', ['--file', '.my-test-file-env'])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'uses the user-specified filename to read example environment' do
|
50
|
+
fake_consolidator = double
|
51
|
+
expect(fake_consolidator).to receive(:run)
|
52
|
+
expect(Dotenvious::CLI::EnvFileConsolidator).to receive(:new)
|
53
|
+
.with({example_file: '.my-test-file-env'})
|
54
|
+
.and_return(fake_consolidator)
|
55
|
+
|
56
|
+
described_class.new.run
|
57
|
+
end
|
58
|
+
end
|
26
59
|
end
|
27
60
|
end
|
28
61
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dotenvious::Loaders::DotenvFile 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 Dotenv format file and returns hash' do
|
20
|
+
expect(File).to receive(:read).and_return "TEST=123\nEXAMPLE=234"
|
21
|
+
|
22
|
+
response = described_class.load_from('.env')
|
23
|
+
|
24
|
+
expect(response['TEST']).to eq '123'
|
25
|
+
expect(response['EXAMPLE']).to eq '234'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,12 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dotenvious::Loaders::Environments do
|
4
|
-
describe '#
|
5
|
-
it '
|
6
|
-
|
7
|
-
|
4
|
+
describe '#new' do
|
5
|
+
it 'takes options hash' do
|
6
|
+
expect{ described_class.new({example_file: '.my.example.file'}) }.to_not raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#load_environments' do
|
11
|
+
context 'without user-specified example file' do
|
12
|
+
it 'loads from Dotenv as well as Loaders::Example' do
|
13
|
+
expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.env').and_return({})
|
14
|
+
expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.example-env').and_return({})
|
15
|
+
|
16
|
+
described_class.new.load_environments
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with user-specified example file' do
|
21
|
+
it 'loads that example environment' do
|
22
|
+
expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.env').and_return({})
|
23
|
+
expect(Dotenvious::Loaders::DotenvFile).to receive(:load_from).with('.my.example.file').and_return({})
|
8
24
|
|
9
|
-
|
25
|
+
described_class.new({example_file: '.my.example.file'}).load_environments
|
26
|
+
end
|
10
27
|
end
|
11
28
|
end
|
12
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenvious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Faris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,10 +72,8 @@ files:
|
|
72
72
|
- lib/dotenvious/configuration.rb
|
73
73
|
- lib/dotenvious/env_appender.rb
|
74
74
|
- lib/dotenvious/loaders/configuration.rb
|
75
|
-
- lib/dotenvious/loaders/
|
76
|
-
- lib/dotenvious/loaders/environment.rb
|
75
|
+
- lib/dotenvious/loaders/dotenv_file.rb
|
77
76
|
- lib/dotenvious/loaders/environments.rb
|
78
|
-
- lib/dotenvious/loaders/example.rb
|
79
77
|
- lib/dotenvious/mismatched_variable_finder.rb
|
80
78
|
- lib/dotenvious/missing_variable_finder.rb
|
81
79
|
- lib/dotenvious/prompter.rb
|
@@ -86,9 +84,8 @@ files:
|
|
86
84
|
- spec/dotenvious/configuration_spec.rb
|
87
85
|
- spec/dotenvious/env_appender_spec.rb
|
88
86
|
- spec/dotenvious/loaders/configuration_spec.rb
|
89
|
-
- spec/dotenvious/loaders/
|
87
|
+
- spec/dotenvious/loaders/dotenv_file_spec.rb
|
90
88
|
- spec/dotenvious/loaders/environments_spec.rb
|
91
|
-
- spec/dotenvious/loaders/example_spec.rb
|
92
89
|
- spec/dotenvious/mismatched_variable_finder_spec.rb
|
93
90
|
- spec/dotenvious/missing_variable_finder_spec.rb
|
94
91
|
- spec/dotenvious/prompter_spec.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dotenvious::Loaders::Env do
|
4
|
-
describe '#load' do
|
5
|
-
context 'when .env are not present' do
|
6
|
-
before do
|
7
|
-
expect(File).to receive(:exists?).and_return false
|
8
|
-
end
|
9
|
-
it 'aborts the process' do
|
10
|
-
described_class.new.load
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when .env is present' do
|
15
|
-
before do
|
16
|
-
expect(File).to receive(:exists?).and_return true
|
17
|
-
end
|
18
|
-
it 'loads files from .env' do
|
19
|
-
expect(File).to receive(:read).with('.env').and_return ""
|
20
|
-
|
21
|
-
described_class.new.load
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'passes those arguments to Dotenvious::ENV_EXAMPLE' do
|
25
|
-
expect(File).to receive(:read).and_return "TEST=123\nEXAMPLE=234"
|
26
|
-
|
27
|
-
described_class.new.load
|
28
|
-
|
29
|
-
expect(Dotenvious::ENV['TEST']).to eq '123'
|
30
|
-
expect(Dotenvious::ENV['EXAMPLE']).to eq '234'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dotenvious::Loaders::Example do
|
4
|
-
describe '#load' do
|
5
|
-
context 'when example-env does not exist' do
|
6
|
-
before do
|
7
|
-
expect(File).to receive(:exists?).and_return false
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'aborts the process' do
|
11
|
-
described_class.new.load
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when example-env exists' do
|
16
|
-
before do
|
17
|
-
expect(File).to receive(:exists?).and_return true
|
18
|
-
stub_const('Dotenvious::DEFAULT_EXAMPLE_ENV_FILE', '.example-env')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'loads files from Dotenvious::DEFAULT_EXAMPLE_ENV_FILE' do
|
22
|
-
expect(File).to receive(:read).with('.example-env').and_return ""
|
23
|
-
|
24
|
-
described_class.new.load
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'passes those arguments to Dotenvious::ENV_EXAMPLE' do
|
28
|
-
expect(File).to receive(:read).and_return "TEST=123\nEXAMPLE=234"
|
29
|
-
|
30
|
-
described_class.new.load
|
31
|
-
|
32
|
-
expect(Dotenvious::ENV_EXAMPLE['TEST']).to eq '123'
|
33
|
-
expect(Dotenvious::ENV_EXAMPLE['EXAMPLE']).to eq '234'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|