Class: Hook
- Inherits:
-
Object
show all
- Defined in:
- lib/dot_example/hook.rb
Instance Method Summary
collapse
Instance Method Details
#contains_steps? ⇒ Boolean
42
43
44
|
# File 'lib/dot_example/hook.rb', line 42
def contains_steps?
contents.include?(steps)
end
|
#contents ⇒ Object
10
11
12
|
# File 'lib/dot_example/hook.rb', line 10
def contents
File.read(filepath)
end
|
#create_file ⇒ Object
24
25
26
27
28
|
# File 'lib/dot_example/hook.rb', line 24
def create_file
%x[ touch #{filepath} ]
%x[ chmod +x #{filepath} ]
print_new_hook_message
end
|
#create_file_if_does_not_exist ⇒ Object
18
19
20
21
22
|
# File 'lib/dot_example/hook.rb', line 18
def create_file_if_does_not_exist
unless Dir.glob(filepath).any?
create_file
end
end
|
#filepath ⇒ Object
14
15
16
|
# File 'lib/dot_example/hook.rb', line 14
def filepath
File.join(".git", "hooks", type)
end
|
#find_or_create ⇒ Object
30
31
|
# File 'lib/dot_example/hook.rb', line 30
def find_or_create
end
|
#print_new_hook_message ⇒ Object
2
3
4
|
# File 'lib/dot_example/hook.rb', line 2
def print_new_hook_message
puts Paint["New #{type} hook created", :green]
end
|
#print_new_steps_message ⇒ Object
6
7
8
|
# File 'lib/dot_example/hook.rb', line 6
def print_new_steps_message
puts Paint[ "New steps added to #{type} hook\n#{steps}", :green]
end
|
#write! ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/dot_example/hook.rb', line 33
def write!
unless contains_steps?
File.open(filepath, "a") do |file|
file.puts steps
end
print_new_steps_message
end
end
|