dotenvgen 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/dotenvgen +69 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42dc6375c174c2f6b540f0f8b6203b3599c36215
4
+ data.tar.gz: 20aa790068383f229fe5dd8586469611dcc864a9
5
+ SHA512:
6
+ metadata.gz: 4dd4f4a886b16964113a4cba873e7f8d21156e5c6407ebc8e8b9c8e7742887c576edd7f44731c9e530eafabf00813b1b266c220e8b886da0b8575fd6e2af6683
7
+ data.tar.gz: 1b21b5c419d916c7daeb0c7edaf1cb4b7221f4f54742e3e03cfe28071952e31d82c76f1fbfa7798e3b3092a595e24d1fa6424e2f8d65c0f1b36435a5d704da0d
data/bin/dotenvgen ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class Dsl
4
+ def initialize
5
+
6
+ # for each group (i.e. prod, test, dev, etc.), there is a list of hashes
7
+ # (key-value pairs)
8
+ # FIXME: store a single hash for each group to prevent duplicate keys
9
+ @group_data = {}
10
+
11
+ @current_groups = {}
12
+ end
13
+
14
+ def group *groups, &block
15
+ @current_groups = groups
16
+ yield
17
+ end
18
+
19
+ def env key, value
20
+ @current_groups.each do |g|
21
+ @group_data[g] = [] if @group_data[g] == nil
22
+ @group_data[g] << { key => value }
23
+ end
24
+ end
25
+
26
+ def run
27
+ path = File.expand_path("Envfile")
28
+ begin
29
+ f = File.open(path, "rb", &:read)
30
+ rescue
31
+ puts "Couldn't locate an Envfile"
32
+ exit 1
33
+ end
34
+ instance_eval(f, path, 1)
35
+
36
+ @group_data.each do |group, pairs|
37
+ pairs.sort_by!{|hash|hash.keys[0]}
38
+ end
39
+ end
40
+
41
+ def write
42
+ @group_data.each do |group, pairs|
43
+ str = ""
44
+ pairs.each do |h|
45
+ h.each do |k, v|
46
+ str << "#{k}=\"#{v}\"\n"
47
+ end
48
+ end
49
+ fname = ".env.#{group}"
50
+ if File.exist?(fname)
51
+ print "#{fname} exists. overwrite? (y/n) "
52
+ unless /(Y|y)((E|e)(s|S))?/.match gets
53
+ next
54
+ end
55
+ puts "#{fname} overwritten"
56
+ end
57
+ File.open(fname, "w") do |f|
58
+ f.puts str
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ if __FILE__ == $PROGRAM_NAME
66
+ dsl = Dsl.new
67
+ dsl.run
68
+ dsl.write
69
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotenvgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Tiger Chow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables:
16
+ - dotenvgen
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/dotenvgen
21
+ homepage:
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.5.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Generate environment specific .env (dotenv) files
45
+ test_files: []