dot_example 1.0.0.pre → 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.
- checksums.yaml +4 -4
- data/bin/dot_example +1 -2
- data/lib/dot_example.rb +4 -3
- data/lib/dot_example/dot_env.rb +13 -0
- data/lib/dot_example/dot_env_dot_example.rb +13 -11
- data/lib/dot_example/hook.rb +43 -0
- data/lib/dot_example/post_checkout_hook.rb +3 -43
- data/lib/dot_example/pre_commit_hook.rb +10 -41
- data/lib/dot_example/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 365654bfa095736ff800a703bfe73956a8d173a6
|
|
4
|
+
data.tar.gz: a7423c998b417766cc91efc9e5245ff20cbee3ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e3ff98eeb23f76b6b625976273fd7cdc059f6bdda44bbd5b9b7a1a4afb4e070b256ad00bdf5da04bb1d511dd447531b7ff9354bfd6ad838266449ea5056057
|
|
7
|
+
data.tar.gz: c1a58fe13901b25658751823951a9b68c1e4768dd8cca82f35051af28dcf0e5e434846c6696dd3207920e0b2b2a37a32377ef534e2d6ab6a79c701685c26a3f1
|
data/bin/dot_example
CHANGED
|
@@ -17,8 +17,7 @@ command :setup do |c|
|
|
|
17
17
|
#c.example 'description', 'command example'
|
|
18
18
|
#c.option '--some-switch', 'Some switch that does something'
|
|
19
19
|
c.action do |args, options|
|
|
20
|
-
|
|
21
|
-
DotExample.add_pre_commit_hook(dot_env_dot_example)
|
|
20
|
+
DotExample.add_pre_commit_hook
|
|
22
21
|
DotExample.add_post_checkout_hook
|
|
23
22
|
end
|
|
24
23
|
end
|
data/lib/dot_example.rb
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
require 'paint'
|
|
1
2
|
require_relative "dot_example/version"
|
|
2
3
|
require_relative "dot_example/dot_env"
|
|
3
4
|
require_relative "dot_example/dot_env_dot_example"
|
|
5
|
+
require_relative "dot_example/hook"
|
|
4
6
|
require_relative "dot_example/pre_commit_hook"
|
|
5
7
|
require_relative "dot_example/post_checkout_hook"
|
|
6
|
-
require_relative "dot_example/hook"
|
|
7
8
|
|
|
8
9
|
module DotExample
|
|
9
10
|
def self.add_pre_commit_hook(dot_env_dot_example)
|
|
10
|
-
pre_commit_hook = PreCommitHook.
|
|
11
|
+
pre_commit_hook = PreCommitHook.new
|
|
11
12
|
pre_commit_hook.write!
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def self.add_post_checkout_hook
|
|
15
|
-
post_checkout_hook = PostCheckoutHook.
|
|
16
|
+
post_checkout_hook = PostCheckoutHook.new
|
|
16
17
|
post_checkout_hook.write!
|
|
17
18
|
end
|
|
18
19
|
end
|
data/lib/dot_example/dot_env.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class DotEnv
|
|
2
2
|
def initialize(filename = nil)
|
|
3
3
|
@filename = filename || ".env"
|
|
4
|
+
create_file_if_does_not_exist
|
|
4
5
|
end
|
|
5
6
|
|
|
6
7
|
attr_reader :filename
|
|
@@ -22,6 +23,18 @@ class DotEnv
|
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
|
|
26
|
+
def create_file_if_does_not_exist
|
|
27
|
+
unless Dir.glob(filename).any?
|
|
28
|
+
create_file
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_file
|
|
33
|
+
%x[ touch #{filename} ]
|
|
34
|
+
puts Paint[".env created", :green]
|
|
35
|
+
# TODO: Add to .gitignore if it's not there already.
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
private
|
|
26
39
|
|
|
27
40
|
def lines
|
|
@@ -10,34 +10,36 @@ class DotEnvDotExample
|
|
|
10
10
|
if keys_new_to_example.any?
|
|
11
11
|
print_new_keys_message
|
|
12
12
|
File.open(filename, "a") do |file|
|
|
13
|
-
file.puts keys_new_to_example
|
|
13
|
+
file.puts keys_new_to_example.map { |key| "#{key}=" }
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def keys_new_to_example
|
|
19
|
-
dot_env.keys
|
|
19
|
+
dot_env.keys.reject do |key|
|
|
20
|
+
keys.map(&:chomp).include? key
|
|
21
|
+
end
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def print_new_keys_message
|
|
23
|
-
puts
|
|
24
|
-
|
|
25
|
+
puts Paint[
|
|
26
|
+
"New variables added to #{filename}",
|
|
27
|
+
:green
|
|
28
|
+
]
|
|
25
29
|
puts keys_new_to_example
|
|
26
|
-
puts "*" * 60
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def missing_keys
|
|
30
|
-
keys.reject
|
|
31
|
-
dot_env.keys.include?(key)
|
|
32
|
-
end
|
|
33
|
+
keys.reject { |key| dot_env.keys.include?(key) }
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
def print_missing_keys_message
|
|
36
37
|
if missing_keys.any?
|
|
37
|
-
puts
|
|
38
|
-
|
|
38
|
+
puts Paint[
|
|
39
|
+
"missing ENV variables from #{dot_env.filename}",
|
|
40
|
+
:green
|
|
41
|
+
]
|
|
39
42
|
puts missing_keys
|
|
40
|
-
puts "*" * 60
|
|
41
43
|
end
|
|
42
44
|
end
|
|
43
45
|
|
data/lib/dot_example/hook.rb
CHANGED
|
@@ -1,2 +1,45 @@
|
|
|
1
1
|
class Hook
|
|
2
|
+
def print_new_hook_message
|
|
3
|
+
puts Paint["New #{type} hook created", :green]
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def print_new_steps_message
|
|
7
|
+
puts Paint[ "New steps added to #{type} hook\n#{steps}", :green]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def contents
|
|
11
|
+
File.read(filepath)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def filepath
|
|
15
|
+
File.join(".git", "hooks", type)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_file_if_does_not_exist
|
|
19
|
+
unless Dir.glob(filepath).any?
|
|
20
|
+
create_file
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_file
|
|
25
|
+
%x[ touch #{filepath} ]
|
|
26
|
+
%x[ chmod +x #{filepath} ]
|
|
27
|
+
print_new_hook_message
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def find_or_create
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def write!
|
|
34
|
+
unless contains_steps?
|
|
35
|
+
File.open(filepath, "a") do |file|
|
|
36
|
+
file.puts steps
|
|
37
|
+
end
|
|
38
|
+
print_new_steps_message
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def contains_steps?
|
|
43
|
+
contents.include?(steps)
|
|
44
|
+
end
|
|
2
45
|
end
|
|
@@ -1,51 +1,11 @@
|
|
|
1
1
|
class PostCheckoutHook < Hook
|
|
2
|
-
FILEPATH = File.join(".git", "hooks", "post-checkout")
|
|
3
|
-
|
|
4
2
|
def initialize(dot_env_dot_example = nil)
|
|
5
3
|
@dot_env_dot_example = dot_env_dot_example || DotEnvDotExample.new
|
|
6
|
-
@
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
attr_reader :dot_env_dot_example, :name
|
|
10
|
-
|
|
11
|
-
def self.find_or_create
|
|
12
|
-
unless Dir.glob(FILEPATH).any?
|
|
13
|
-
%x[ touch #{FILEPATH} ]
|
|
14
|
-
%x[ chmod +x #{FILEPATH} ]
|
|
15
|
-
self.print_new_hook_message
|
|
16
|
-
end
|
|
17
|
-
new
|
|
4
|
+
@type = "post-checkout"
|
|
5
|
+
create_file_if_does_not_exist
|
|
18
6
|
end
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
unless contains_steps?
|
|
22
|
-
File.open(FILEPATH, "a") do |file|
|
|
23
|
-
file.puts steps
|
|
24
|
-
end
|
|
25
|
-
print_new_steps_message
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.print_new_hook_message
|
|
30
|
-
puts "*" * 60
|
|
31
|
-
puts "New #{name} hook created"
|
|
32
|
-
puts "*" * 60
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def print_new_steps_message
|
|
36
|
-
puts "*" * 60
|
|
37
|
-
puts "New steps added to #{name} hook"
|
|
38
|
-
puts steps
|
|
39
|
-
puts "*" * 60
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def contains_steps?
|
|
43
|
-
contents.include?(steps)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def contents
|
|
47
|
-
File.read(FILEPATH)
|
|
48
|
-
end
|
|
8
|
+
attr_reader :dot_env_dot_example, :type
|
|
49
9
|
|
|
50
10
|
def steps
|
|
51
11
|
"dot_example check"
|
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
require_relative './hook'
|
|
2
|
-
|
|
3
1
|
class PreCommitHook < Hook
|
|
4
|
-
FILEPATH = File.join(".git", "hooks", "pre-commit")
|
|
5
|
-
|
|
6
2
|
def initialize(dot_env_dot_example = nil)
|
|
7
3
|
@dot_env_dot_example = dot_env_dot_example || DotEnvDotExample.new
|
|
4
|
+
@type = "pre-commit"
|
|
5
|
+
create_file_if_does_not_exist
|
|
8
6
|
end
|
|
9
7
|
|
|
10
|
-
attr_reader :dot_env_dot_example
|
|
11
|
-
|
|
12
|
-
def self.find_or_create
|
|
13
|
-
unless Dir.glob(FILEPATH).any?
|
|
14
|
-
%x[ touch #{FILEPATH} ]
|
|
15
|
-
%x[ chmod +x #{FILEPATH} ]
|
|
16
|
-
self.print_new_pre_commit_hook_message
|
|
17
|
-
end
|
|
18
|
-
new
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.print_new_pre_commit_hook_message
|
|
22
|
-
puts "*" * 60
|
|
23
|
-
puts "New pre-commit hook created"
|
|
24
|
-
puts "*" * 60
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def write!
|
|
28
|
-
unless contains_dot_example_steps?
|
|
29
|
-
File.open(FILEPATH, "a") do |file|
|
|
30
|
-
file.puts dot_env_dot_example.pre_commit_hook
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def print_new_steps_message
|
|
36
|
-
puts "*" * 60
|
|
37
|
-
puts "New steps added to pre-commit hook"
|
|
38
|
-
puts dot_env_dot_example.pre_commit_hook
|
|
39
|
-
puts "*" * 60
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def contents
|
|
43
|
-
File.read(FILEPATH)
|
|
44
|
-
end
|
|
8
|
+
attr_reader :dot_env_dot_example, :type
|
|
45
9
|
|
|
46
|
-
|
|
47
|
-
|
|
10
|
+
# TODO: Make it possible to put .env and .env.example files somewhere else?
|
|
11
|
+
# Maybe later if people actually want this feature
|
|
12
|
+
def steps
|
|
13
|
+
[
|
|
14
|
+
"dot_example sync",
|
|
15
|
+
"git add .env.example"
|
|
16
|
+
].join("\n")
|
|
48
17
|
end
|
|
49
18
|
end
|
data/lib/dot_example/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dot_example
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephen Mariano Cabrera
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-09-
|
|
11
|
+
date: 2016-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: commander
|
|
@@ -44,6 +44,20 @@ dependencies:
|
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
46
|
version: 2.1.1
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: paint
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - '='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.0.0
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - '='
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 1.0.0
|
|
47
61
|
- !ruby/object:Gem::Dependency
|
|
48
62
|
name: bundler
|
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -141,9 +155,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
141
155
|
version: '0'
|
|
142
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
157
|
requirements:
|
|
144
|
-
- - "
|
|
158
|
+
- - ">="
|
|
145
159
|
- !ruby/object:Gem::Version
|
|
146
|
-
version:
|
|
160
|
+
version: '0'
|
|
147
161
|
requirements: []
|
|
148
162
|
rubyforge_project:
|
|
149
163
|
rubygems_version: 2.4.8
|